SlideShare a Scribd company logo
What is Python?
Python is a popular programming language. It was
created by Guido van Rossum, and released in 1991.
It is used for:
web development (server-side),
software development,
mathematics,
system scripting.
What can Python do?
• Python can be used on a server to create web applications.
• Python can be used alongside software to create workflows.
• Python can connect to database systems. It can also read
and modify files.
• Python can be used to handle big data and perform complex
mathematics.
• Python can be used for rapid prototyping, or for production-
ready software development.
Why Python?
• Python works on different platforms (Windows, Mac, Linux,
Raspberry Pi, etc).
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping
can be very quick.
• Python can be treated in a procedural way, an object-oriented
way or a functional way.
example print("Hello, World!")
Variables
• Variables are containers for storing data values.
Creating Variables
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a value to it.
input
x = 5
y = "John"
print(x)
print(y)
Output
5
John
Variables do not need to be declared with any particular type, and can even
change type after they have been set.
Example
x = 4 # x is of type int
x = "Sally" # x is now of type str
print(x)
output
Sally
Casting
• If you want to specify the data type of a variable, this
can be done with casting.
• Example
• x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Out put will be
3
3
3.0
• Variable Names
• A variable can have a short name (like x and y) or a
more descriptive name (age, carname, total_volume).
Rules for Python variables:A variable name must start
with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE
are three different variables)
• A variable name cannot be any of the Python keywords.
• Example
• Legal variable names:
• myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
print(myvar)
print(my_var)
print(_my_var)
print(myVar)
print(MYVAR)
print(myvar2)
Many Values to Multiple Variables
• Python allows you to assign values to multiple variables in one line:
• Example
• x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
output will be
?
?
?
One Value to Multiple Variables
• you can assign the same value to multiple variables in one line:
• Example
• x = y = z = "Orange"
print(x)
print(y)
print(z)
• Output
• Orange
Orange
Orange
• Unpack a Collection
• If you have a collection of values in a list, tuple etc. Python
allows you to extract the values into variables. This is
called unpacking.
• Example
• Unpack a list:
• fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Output
apple
banana
cherry
Output Variables
The Python print() function is often used to output variables.
• Example
• x = "Python is awesome"
print(x)
• Variables that are created outside of a function (as in all of the examples in the
previous pages) are known as global variables.
• Global variables can be used by everyone, both inside of functions and outside.
• Example
• Create a variable outside of a function, and use it inside the function
• x = "awesome"
def myfunc():
print("Python is " + x)
myfunc()
Output
Python is awesome
You can display a string literal with the print() function:
• Quotes Inside Quotes
• You can use quotes inside a string, as long as they don't
match the quotes surrounding the string:
• Example
• print("It's alright")
print("He is called 'Johnny'")
print('He is called "Johnny"')
• Control Structures in Python
• Most programs don't operate by carrying out a straightforward sequence of
statements. A code is written to allow making choices and several pathways
through the program to be followed depending on shifts in variable values.
• All programming languages contain a pre-included set of control structures
that enable these control flows to execute, which makes it conceivable.
• This tutorial will examine how to add loops and branches, i.e., conditions to
our Python programs.
• Types of Control Structures
• Control flow refers to the sequence a program will follow during its
execution.
•Repetition - This structure is used for looping, i.e., repeatedly executing a certain piece of a code
block.
Sequential
Sequential statements are a set of statements whose execution process happens in a sequence.
The problem with sequential statements is that if the logic has
broken in any one of the lines, then the complete source code execution will break.
Code
1.# Python program to show how a sequential control structure works
2.
3.# We will initialize some variables
4.# Then operations will be done
5.# And, at last, results will be printed
6.# Execution flow will be the same as the code is written, and there is no hidden flow
7.a = 20
8.b = 10
9.c = a - b
10.d = a + b
11.e = a * b
12.print("The result of the subtraction is: ", c)
13.print("The result of the addition is: ", d)
14.print("The result of the multiplication is: ", e)
Output:
The result of the subtraction is: 10 The result of the addition is : 30 The result of the multiplication is: 200
Selection/Decision Control Statements
• The statements used in selection control structures are also referred to as branching statements or, as their
fundamental role is to make decisions, decision control statements.
• A program can test many conditions using these selection statements, and depending on whether the given
condition is true or not, it can execute different code blocks.
• There can be many forms of decision control structures. Here are some most commonly used control structures:
• Only if
• if-else
• The nested if
• The complete if-elif-else
• Simple if
• If statements in Python are called control flow statements. The selection statements assist us in running a
certain piece of code, but only in certain circumstances. There is only one condition to test in a basic if statement.
• The if statement's fundamental structure is as follows:
• Syntax
1. if <conditional expression> :
2. The code block to be executed if the condition is True
• These statements will always be executed. They are part of the main code.
• All the statements written indented after the if statement will run if the condition giver after the if the keyword is
True. Only the code statement that will always be executed regardless of the if the condition is the statement
written aligned to the main code. Python uses these types of indentations to identify a code block of a particular
control flow statement. The specified control structure will alter the flow of only those indented statements.
1.# Python program to show how a simple if keyword works
2.
3.# Initializing some variables
4.v = 5
5.t = 4
6.print("The initial value of v is", v, "and that of t is ",t)
7.
8.# Creating a selection control structure
9.if v > t :
10. print(v, "is bigger than ", t)
11. v -= 2
12.
13.print("The new value of v is", v, "and the t is ",t)
14.
15.# Creating the second control structure
16.if v < t :
17. print(v , "is smaller than ", t)
18. v += 1
19.
20.print("the new value of v is ", v)
21.
22.# Creating the third control structure
23.if v == t:
24. print("The value of v, ", v, " and t,", t, ", are equal")
Output:
ADVERTISEMENT
The initial value of v is 5 and that of t is 4 5 is bigger than 4 The new value of v is 3 and the t is 4 3 is smaller
than 4 the new value of v is 4 The value of v, 4 and t, 4, are equal
Code
1.# Python program to show how a simple if keyword works
2.
3.# Initializing some variables
4.v = 5
5.t = 4
6.print("The initial value of v is", v, "and that of t is ",t)
7.
8.# Creating a selection control structure
9.if v > t :
10. print(v, "is bigger than ", t)
11. v -= 2
12.
13.print("The new value of v is", v, "and the t is ",t)
14.
15.# Creating the second control structure
16.if v < t :
17. print(v , "is smaller than ", t)
18. v += 1
19.
20.print("the new value of v is ", v)
21.
22.# Creating the third control structure
23.if v == t:
24. print("The value of v, ", v, " and t,", t, ", are equal")
Output:
ADVERTISEMENT
The initial value of v is 5 and that of t is 4 5 is bigger than 4 The new value of v is 3 and the t is 4 3 is smaller than 4 the new value of v is 4 The value of v, 4 and t, 4, are equal
Loops
• A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary,
a set, or a string).
• This is less like the for keyword in other programming languages, and works more like
an iterator method as found in other object-orientated programming languages.With
the for loop we can execute a set of statements, once for each item in a list, tuple, set
etc.
• Example
• Print each fruit in a fruit list:
• fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
output
•
apple
banana
cherry
• For I in range(1,6):
• Print(i)
Looping Through a String
• Even strings are iterable objects, they contain a sequence of characters:
• Example
• Loop through the letters in the word "banana":
• for x in "banana":
print(x)
Output
b
a
n
a
n
a
The break Statement
With the break statement we can stop the loop before it has looped
through all the items:
Example
Exit the loop when x is "banana":
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
applet
The continue Statement
• With the continue statement we can stop the current iteration of
the loop, and continue with the next:
• Example
• Do not print banana:
• fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
Output
apple
cherry
The range() Function
• To loop through a set of code a specified number of times, we can use
the range() function,
• The range() function returns a sequence of numbers, starting from 0
by default, and increments by 1 (by default), and ends at a specified
number.
• Example
• Using the range() function:
• for x in range(6):
print(x)
output
0
1
2
3
4
5
The range() function defaults to increment the sequence by 1, however
it is possible to specify the increment value by adding a third
parameter: range(2, 30, 3):
• Example
• Increment the sequence with 3 (default is 1):
• for x in range(2, 30, 3):
print(x)
Output
2
5
8
11
14
17
20
23
26
29
Else in For Loop
The else keyword in a for loop specifies a block of code to be executed
when
the loop is finished:
Example
Print all numbers from 0 to 5, and print a message when the loop has
ended:
for x in range(6):
print(x)
else:
print("Finally finished!")
output
0
1
2
3
4
5
Finally finished!
happens with the else block:
for x in range(6):
if x == 3: break
print(x)
else:
print("Finally finished!")
Output
0
1
2

More Related Content

PPTX
Presgfdjfwwwwwwwwwwqwqeeqentation11.pptx
PPTX
Basic concept of Python.pptx includes design tool, identifier, variables.
PPTX
Review of C programming language.pptx...
PPTX
python_class.pptx
PPTX
IoT-Week1-Day1-Lab.pptx
PDF
Introduction-to-Python-print-datatype.pdf
PDF
Python basics_ part1
PPTX
Python Basics by Akanksha Bali
Presgfdjfwwwwwwwwwwqwqeeqentation11.pptx
Basic concept of Python.pptx includes design tool, identifier, variables.
Review of C programming language.pptx...
python_class.pptx
IoT-Week1-Day1-Lab.pptx
Introduction-to-Python-print-datatype.pdf
Python basics_ part1
Python Basics by Akanksha Bali

Similar to python BY ME-2021python anylssis(1).pptx (20)

PDF
Python (3).pdf
PPTX
Unit - 2 CAP.pptx
PPT
Control structures pyhton
PPTX
Python fundamentals
PPTX
Review Python
PPTX
Chapter 1 Python Revision (1).pptx the royal ac acemy
PPTX
Looping in PythonLab8 lecture slides.pptx
PDF
Python Decision Making And Loops.pdf
PPTX
lecture 2.pptx
DOCX
INTERNSHIP REPORT.docx
PPTX
modul-python-all.pptx
PPTX
Pythonppt28 11-18
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
PPTX
Python for beginner, learn python from scratch.pptx
PPT
Python
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
PPTX
Python basics
Python (3).pdf
Unit - 2 CAP.pptx
Control structures pyhton
Python fundamentals
Review Python
Chapter 1 Python Revision (1).pptx the royal ac acemy
Looping in PythonLab8 lecture slides.pptx
Python Decision Making And Loops.pdf
lecture 2.pptx
INTERNSHIP REPORT.docx
modul-python-all.pptx
Pythonppt28 11-18
FUNDAMENTALS OF PYTHON LANGUAGE
Python for beginner, learn python from scratch.pptx
Python
Python basics
Python basics
Python basics
Python basics
Python basics
Ad

Recently uploaded (20)

PDF
Prostaglandin E2.pdf orthoodontics op kharbanda
PPTX
Overview Planner of Soft Skills in a single ppt
PDF
L-0018048598visual cloud book for PCa-pdf.pdf
PDF
Blue-Modern-Elegant-Presentation (1).pdf
PPT
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
PPTX
Principles of Inheritance and variation class 12.pptx
PDF
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
PPTX
Definition and Relation of Food Science( Lecture1).pptx
DOCX
How to Become a Criminal Profiler or Behavioural Analyst.docx
PPTX
The Stock at arrangement the stock and product.pptx
PDF
Understanding the Rhetorical Situation Presentation in Blue Orange Muted Il_2...
PPTX
PMP (Project Management Professional) course prepares individuals
PPTX
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
PPTX
Cerebral_Palsy_Detailed_Presentation.pptx
PPT
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
PPTX
Your Guide to a Winning Interview Aug 2025.
PPTX
microtomy kkk. presenting to cryst in gl
PPTX
internship presentation of bsnl in colllege
PDF
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
PDF
Biography of Mohammad Anamul Haque Nayan
Prostaglandin E2.pdf orthoodontics op kharbanda
Overview Planner of Soft Skills in a single ppt
L-0018048598visual cloud book for PCa-pdf.pdf
Blue-Modern-Elegant-Presentation (1).pdf
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
Principles of Inheritance and variation class 12.pptx
313302 DBMS UNIT 1 PPT for diploma Computer Eng Unit 2
Definition and Relation of Food Science( Lecture1).pptx
How to Become a Criminal Profiler or Behavioural Analyst.docx
The Stock at arrangement the stock and product.pptx
Understanding the Rhetorical Situation Presentation in Blue Orange Muted Il_2...
PMP (Project Management Professional) course prepares individuals
PE3-WEEK-3sdsadsadasdadadwadwdsdddddd.pptx
Cerebral_Palsy_Detailed_Presentation.pptx
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
Your Guide to a Winning Interview Aug 2025.
microtomy kkk. presenting to cryst in gl
internship presentation of bsnl in colllege
Why Today’s Brands Need ORM & SEO Specialists More Than Ever.pdf
Biography of Mohammad Anamul Haque Nayan
Ad

python BY ME-2021python anylssis(1).pptx

  • 1. What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side), software development, mathematics, system scripting.
  • 2. What can Python do? • Python can be used on a server to create web applications. • Python can be used alongside software to create workflows. • Python can connect to database systems. It can also read and modify files. • Python can be used to handle big data and perform complex mathematics. • Python can be used for rapid prototyping, or for production- ready software development.
  • 3. Why Python? • Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). • Python has a simple syntax similar to the English language. • Python has syntax that allows developers to write programs with fewer lines than some other programming languages. • Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. • Python can be treated in a procedural way, an object-oriented way or a functional way.
  • 4. example print("Hello, World!") Variables • Variables are containers for storing data values. Creating Variables • Python has no command for declaring a variable. • A variable is created the moment you first assign a value to it. input x = 5 y = "John" print(x) print(y) Output 5 John
  • 5. Variables do not need to be declared with any particular type, and can even change type after they have been set. Example x = 4 # x is of type int x = "Sally" # x is now of type str print(x) output Sally
  • 6. Casting • If you want to specify the data type of a variable, this can be done with casting. • Example • x = str(3) # x will be '3' y = int(3) # y will be 3 z = float(3) # z will be 3.0 Out put will be 3 3 3.0
  • 7. • Variable Names • A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables:A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case-sensitive (age, Age and AGE are three different variables) • A variable name cannot be any of the Python keywords.
  • 8. • Example • Legal variable names: • myvar = "John" my_var = "John" _my_var = "John" myVar = "John" MYVAR = "John" myvar2 = "John" print(myvar) print(my_var) print(_my_var) print(myVar) print(MYVAR) print(myvar2)
  • 9. Many Values to Multiple Variables • Python allows you to assign values to multiple variables in one line: • Example • x, y, z = "Orange", "Banana", "Cherry" print(x) print(y) print(z) output will be ? ? ? One Value to Multiple Variables • you can assign the same value to multiple variables in one line: • Example • x = y = z = "Orange" print(x) print(y) print(z) • Output • Orange Orange Orange
  • 10. • Unpack a Collection • If you have a collection of values in a list, tuple etc. Python allows you to extract the values into variables. This is called unpacking. • Example • Unpack a list: • fruits = ["apple", "banana", "cherry"] x, y, z = fruits print(x) print(y) print(z) Output apple banana cherry
  • 11. Output Variables The Python print() function is often used to output variables. • Example • x = "Python is awesome" print(x) • Variables that are created outside of a function (as in all of the examples in the previous pages) are known as global variables. • Global variables can be used by everyone, both inside of functions and outside. • Example • Create a variable outside of a function, and use it inside the function • x = "awesome" def myfunc(): print("Python is " + x) myfunc() Output Python is awesome
  • 12. You can display a string literal with the print() function: • Quotes Inside Quotes • You can use quotes inside a string, as long as they don't match the quotes surrounding the string: • Example • print("It's alright") print("He is called 'Johnny'") print('He is called "Johnny"')
  • 13. • Control Structures in Python • Most programs don't operate by carrying out a straightforward sequence of statements. A code is written to allow making choices and several pathways through the program to be followed depending on shifts in variable values. • All programming languages contain a pre-included set of control structures that enable these control flows to execute, which makes it conceivable. • This tutorial will examine how to add loops and branches, i.e., conditions to our Python programs. • Types of Control Structures • Control flow refers to the sequence a program will follow during its execution.
  • 14. •Repetition - This structure is used for looping, i.e., repeatedly executing a certain piece of a code block. Sequential Sequential statements are a set of statements whose execution process happens in a sequence. The problem with sequential statements is that if the logic has broken in any one of the lines, then the complete source code execution will break. Code 1.# Python program to show how a sequential control structure works 2. 3.# We will initialize some variables 4.# Then operations will be done 5.# And, at last, results will be printed 6.# Execution flow will be the same as the code is written, and there is no hidden flow 7.a = 20 8.b = 10 9.c = a - b 10.d = a + b 11.e = a * b 12.print("The result of the subtraction is: ", c) 13.print("The result of the addition is: ", d) 14.print("The result of the multiplication is: ", e) Output: The result of the subtraction is: 10 The result of the addition is : 30 The result of the multiplication is: 200
  • 15. Selection/Decision Control Statements • The statements used in selection control structures are also referred to as branching statements or, as their fundamental role is to make decisions, decision control statements. • A program can test many conditions using these selection statements, and depending on whether the given condition is true or not, it can execute different code blocks. • There can be many forms of decision control structures. Here are some most commonly used control structures: • Only if • if-else • The nested if • The complete if-elif-else • Simple if • If statements in Python are called control flow statements. The selection statements assist us in running a certain piece of code, but only in certain circumstances. There is only one condition to test in a basic if statement. • The if statement's fundamental structure is as follows: • Syntax 1. if <conditional expression> : 2. The code block to be executed if the condition is True • These statements will always be executed. They are part of the main code. • All the statements written indented after the if statement will run if the condition giver after the if the keyword is True. Only the code statement that will always be executed regardless of the if the condition is the statement written aligned to the main code. Python uses these types of indentations to identify a code block of a particular control flow statement. The specified control structure will alter the flow of only those indented statements.
  • 16. 1.# Python program to show how a simple if keyword works 2. 3.# Initializing some variables 4.v = 5 5.t = 4 6.print("The initial value of v is", v, "and that of t is ",t) 7. 8.# Creating a selection control structure 9.if v > t : 10. print(v, "is bigger than ", t) 11. v -= 2 12. 13.print("The new value of v is", v, "and the t is ",t) 14. 15.# Creating the second control structure 16.if v < t : 17. print(v , "is smaller than ", t) 18. v += 1 19. 20.print("the new value of v is ", v) 21. 22.# Creating the third control structure 23.if v == t: 24. print("The value of v, ", v, " and t,", t, ", are equal") Output: ADVERTISEMENT The initial value of v is 5 and that of t is 4 5 is bigger than 4 The new value of v is 3 and the t is 4 3 is smaller than 4 the new value of v is 4 The value of v, 4 and t, 4, are equal
  • 17. Code 1.# Python program to show how a simple if keyword works 2. 3.# Initializing some variables 4.v = 5 5.t = 4 6.print("The initial value of v is", v, "and that of t is ",t) 7. 8.# Creating a selection control structure 9.if v > t : 10. print(v, "is bigger than ", t) 11. v -= 2 12. 13.print("The new value of v is", v, "and the t is ",t) 14. 15.# Creating the second control structure 16.if v < t : 17. print(v , "is smaller than ", t) 18. v += 1 19. 20.print("the new value of v is ", v) 21. 22.# Creating the third control structure 23.if v == t: 24. print("The value of v, ", v, " and t,", t, ", are equal") Output: ADVERTISEMENT The initial value of v is 5 and that of t is 4 5 is bigger than 4 The new value of v is 3 and the t is 4 3 is smaller than 4 the new value of v is 4 The value of v, 4 and t, 4, are equal
  • 18. Loops • A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). • This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc. • Example • Print each fruit in a fruit list: • fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) output • apple banana cherry • For I in range(1,6): • Print(i)
  • 19. Looping Through a String • Even strings are iterable objects, they contain a sequence of characters: • Example • Loop through the letters in the word "banana": • for x in "banana": print(x) Output b a n a n a
  • 20. The break Statement With the break statement we can stop the loop before it has looped through all the items: Example Exit the loop when x is "banana": fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) if x == "banana": break applet
  • 21. The continue Statement • With the continue statement we can stop the current iteration of the loop, and continue with the next: • Example • Do not print banana: • fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x) Output apple cherry
  • 22. The range() Function • To loop through a set of code a specified number of times, we can use the range() function, • The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number. • Example • Using the range() function: • for x in range(6): print(x) output 0 1 2 3 4 5
  • 23. The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3): • Example • Increment the sequence with 3 (default is 1): • for x in range(2, 30, 3): print(x) Output 2 5 8 11 14 17 20 23 26 29
  • 24. Else in For Loop The else keyword in a for loop specifies a block of code to be executed when the loop is finished: Example Print all numbers from 0 to 5, and print a message when the loop has ended: for x in range(6): print(x) else: print("Finally finished!") output 0 1 2 3 4 5 Finally finished!
  • 25. happens with the else block: for x in range(6): if x == 3: break print(x) else: print("Finally finished!") Output 0 1 2