SlideShare a Scribd company logo
1 of 20
P.INDURANI
ASSISTANT PROFESSOR & HEAD
DEPARTMENT OF COMPUTER SCIENCE
PARVATHY’S ARTS AND SCIENCE COLLEGE
DINDIGUL
11
PYTHON
PROGRAMMING
UNIT I
Introduction – Interactive programming
language.
IDLE – Integrated Development and Learning
Environment.
• >>> - To indicate waiting for a user command.
• To be printed text is enclosed between
apostrophe marks.
eg: >>> print(‘ Hello World’)
2
Example
3
Operators
Precedence of arithmetic operators
• () Parentheses
• ** Exponentiation
• - Negation
• / division // integer division * multiplication %
modulus
• + addition – subtraction
4
Error Message
>>> 10+4(3+3)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
10+4(3+3)
TypeError: 'int' object is not callable
>>> 10/0
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
10/0
ZeroDivisionError: integer division or modulo by zero
>>> 5
Python String
Enclosed within single, double or triple quotes.
6
Relational Operators
• To comparing expression values.
• Yield values: true, false
• ASCII values are used for string comparison
• Does not allow string values to be compared with
numeric values.
Operators are: ==, <, >, <=, >=, !=
7
Operators
Logical Operators
• Combining expressions
• Yield values: true, false
• Involving arithmetic, relational and logical
operators.
• Evaluation using precedence rules.
– Logical: not, and, or
– Operators: arithmetic, relational, logical
Bitwise Operators – Operate bit by bit
8
Variables and Assignment
Statements
• Variables are often called names.
• Binds a variable to an object
• Syntax: variable = expression
Rules:
• Must begin with letter or _ underscore
• Contain any number of letters, digits or underscore.
• Python is case sensitive
• More than one variable may refer to the same
object.
• Shorthand Notation: >> a=a+5
9
Statements
Keywords
• Have special meaning.
• Cannot be used for naming objects.
• Eg: continue, for, while, del, true, def, except,
if, return, and, else, nonlocal, etc.,
Script Mode
• Instruction are written in a file.
• Should have extension .py or .pyw
10
Example
11
Functions
To solve a problem divide it into simpler sub programs.
Built-In Functions
• Input – To get user input.
• Eval – evaluating a string
• Composition – Inner function serves as input argument to
outer function.
• Print – printing multiple values in a single call
• Type – determining data type
• Round – rounding to nearest values
• Min and max – Operands must be compatible for comparison
• Pow – Computing power
• Math – import a module before using it.
12
Function Definition and call
• Comments enhance readability of the code
• Single line comments start with #
• Syntax: def function_name(list_of_parameters):
Eg: def add(a):
• Run - Click run module
• Invoking the function main in the script
Eg: if_name_==‘_main_’:
main()
• The definition of function main
• An if statement
13
Example
14
• for loop: Repeats a set of statements over a group of values.
– Syntax:
for variableName in groupOfValues:
statements
• We indent the statements to be repeated with tabs or spaces.
• variableName gives a name to each value, so you can refer to it in
the statements.
• groupOfValues can be a range of integers, specified with the range
function.
Eg: for x in range(1, 6):
print x, "squared is", x * x
Output:
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
5 squared is 25
Control Structures
15
The range function specifies a range of integers:
• range(start, stop) - the integers between start (inclusive)
and stop (exclusive)
– It can also accept a third value specifying the change between values.
• range(start, stop, step) - the integers between start (inclusive)
and stop (exclusive) by step
– Example:
for x in range(5, 0, -1):
print x
print "Blastoff!"
Output:
5
4
3
2
1
Blastoff!
16
For loop
• Some loops incrementally compute a value that is
initialized outside the loop. This is sometimes called
a cumulative sum.
sum = 0
for i in range(1, 11):
sum = sum + (i * i)
print "sum of first 10 squares is", sum
Output:
sum of first 10 squares is 385
17
Cumulative loop
• if statement: Executes a group of statements only if a
certain condition is true. Otherwise, the statements
are skipped.
– Syntax:
if condition:
statements
• Example:
gpa = 3.4
if gpa > 2.0:
print "Your application is accepted."
18
If statement
• if/else statement: Executes one block of statements if a certain condition is True, and a
second block of statements if it is False.
– Syntax:
if condition:
statements
else:
statements
• Example:
gpa = 1.4
if gpa > 2.0:
print "Welcome to Mars University!"
else:
print "Your application is denied."
• Multiple conditions can be chained with elif ("else if"):
if condition:
statements
elif condition:
statements
else:
statements
19
If…else… statement
• while loop: Executes a group of statements as long as a condition is
True.
– good for indefinite loops (repeat an unknown number of times)
• Syntax:
while condition:
statements
• Example:
number = 1
while number < 200:
print number,
number = number * 2
– Output:
1 2 4 8 16 32 64 128
20
While

More Related Content

What's hot (20)

03 function overloading
03 function overloading03 function overloading
03 function overloading
 
Function overloading(C++)
Function overloading(C++)Function overloading(C++)
Function overloading(C++)
 
This pointer
This pointerThis pointer
This pointer
 
Python advance
Python advancePython advance
Python advance
 
4. python functions
4. python   functions4. python   functions
4. python functions
 
Python modules
Python modulesPython modules
Python modules
 
Python advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresPython advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structures
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Function C++
Function C++ Function C++
Function C++
 
Python libraries
Python librariesPython libraries
Python libraries
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor Python advanced 1.handle error, generator, decorator and decriptor
Python advanced 1.handle error, generator, decorator and decriptor
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Ch7 C++
Ch7 C++Ch7 C++
Ch7 C++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 

Similar to PYTHON PROGRAMMING

TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVAMuskanSony
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelpmeinhomework
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdflailoesakhan
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 
07 control+structures
07 control+structures07 control+structures
07 control+structuresbaran19901990
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answerssheibansari
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The BasicsRanel Padon
 

Similar to PYTHON PROGRAMMING (20)

TEMPLATES IN JAVA
TEMPLATES IN JAVATEMPLATES IN JAVA
TEMPLATES IN JAVA
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Python overview
Python   overviewPython   overview
Python overview
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
Learning c++
Learning c++Learning c++
Learning c++
 
07 control+structures
07 control+structures07 control+structures
07 control+structures
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Python Programming - II. The Basics
Python Programming - II. The BasicsPython Programming - II. The Basics
Python Programming - II. The Basics
 

Recently uploaded

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 

Recently uploaded (20)

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

PYTHON PROGRAMMING

  • 1. P.INDURANI ASSISTANT PROFESSOR & HEAD DEPARTMENT OF COMPUTER SCIENCE PARVATHY’S ARTS AND SCIENCE COLLEGE DINDIGUL 11 PYTHON PROGRAMMING
  • 2. UNIT I Introduction – Interactive programming language. IDLE – Integrated Development and Learning Environment. • >>> - To indicate waiting for a user command. • To be printed text is enclosed between apostrophe marks. eg: >>> print(‘ Hello World’) 2
  • 4. Operators Precedence of arithmetic operators • () Parentheses • ** Exponentiation • - Negation • / division // integer division * multiplication % modulus • + addition – subtraction 4
  • 5. Error Message >>> 10+4(3+3) Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> 10+4(3+3) TypeError: 'int' object is not callable >>> 10/0 Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> 10/0 ZeroDivisionError: integer division or modulo by zero >>> 5
  • 6. Python String Enclosed within single, double or triple quotes. 6
  • 7. Relational Operators • To comparing expression values. • Yield values: true, false • ASCII values are used for string comparison • Does not allow string values to be compared with numeric values. Operators are: ==, <, >, <=, >=, != 7
  • 8. Operators Logical Operators • Combining expressions • Yield values: true, false • Involving arithmetic, relational and logical operators. • Evaluation using precedence rules. – Logical: not, and, or – Operators: arithmetic, relational, logical Bitwise Operators – Operate bit by bit 8
  • 9. Variables and Assignment Statements • Variables are often called names. • Binds a variable to an object • Syntax: variable = expression Rules: • Must begin with letter or _ underscore • Contain any number of letters, digits or underscore. • Python is case sensitive • More than one variable may refer to the same object. • Shorthand Notation: >> a=a+5 9
  • 10. Statements Keywords • Have special meaning. • Cannot be used for naming objects. • Eg: continue, for, while, del, true, def, except, if, return, and, else, nonlocal, etc., Script Mode • Instruction are written in a file. • Should have extension .py or .pyw 10
  • 12. Functions To solve a problem divide it into simpler sub programs. Built-In Functions • Input – To get user input. • Eval – evaluating a string • Composition – Inner function serves as input argument to outer function. • Print – printing multiple values in a single call • Type – determining data type • Round – rounding to nearest values • Min and max – Operands must be compatible for comparison • Pow – Computing power • Math – import a module before using it. 12
  • 13. Function Definition and call • Comments enhance readability of the code • Single line comments start with # • Syntax: def function_name(list_of_parameters): Eg: def add(a): • Run - Click run module • Invoking the function main in the script Eg: if_name_==‘_main_’: main() • The definition of function main • An if statement 13
  • 15. • for loop: Repeats a set of statements over a group of values. – Syntax: for variableName in groupOfValues: statements • We indent the statements to be repeated with tabs or spaces. • variableName gives a name to each value, so you can refer to it in the statements. • groupOfValues can be a range of integers, specified with the range function. Eg: for x in range(1, 6): print x, "squared is", x * x Output: 1 squared is 1 2 squared is 4 3 squared is 9 4 squared is 16 5 squared is 25 Control Structures 15
  • 16. The range function specifies a range of integers: • range(start, stop) - the integers between start (inclusive) and stop (exclusive) – It can also accept a third value specifying the change between values. • range(start, stop, step) - the integers between start (inclusive) and stop (exclusive) by step – Example: for x in range(5, 0, -1): print x print "Blastoff!" Output: 5 4 3 2 1 Blastoff! 16 For loop
  • 17. • Some loops incrementally compute a value that is initialized outside the loop. This is sometimes called a cumulative sum. sum = 0 for i in range(1, 11): sum = sum + (i * i) print "sum of first 10 squares is", sum Output: sum of first 10 squares is 385 17 Cumulative loop
  • 18. • if statement: Executes a group of statements only if a certain condition is true. Otherwise, the statements are skipped. – Syntax: if condition: statements • Example: gpa = 3.4 if gpa > 2.0: print "Your application is accepted." 18 If statement
  • 19. • if/else statement: Executes one block of statements if a certain condition is True, and a second block of statements if it is False. – Syntax: if condition: statements else: statements • Example: gpa = 1.4 if gpa > 2.0: print "Welcome to Mars University!" else: print "Your application is denied." • Multiple conditions can be chained with elif ("else if"): if condition: statements elif condition: statements else: statements 19 If…else… statement
  • 20. • while loop: Executes a group of statements as long as a condition is True. – good for indefinite loops (repeat an unknown number of times) • Syntax: while condition: statements • Example: number = 1 while number < 200: print number, number = number * 2 – Output: 1 2 4 8 16 32 64 128 20 While