Python Revision Tour
Introduction
Python revision Tour- 1
• Introduction to Python
• Working with Python
• Data types , Operations
• Python Functions, Modules
• Flow of execution
• Statement flow control
Python revision Tour- 2
• Sting in python
• List in python
• Tuple in python
• Dictionary in python
Python used as general purpose, high level programming language. Developed by Guido van Rossum in 1991.
Pros of Python :
• Easy to use – Due to simple syntax rule
• Interpreted language – Code execution & interpretation line by line
• Cross-platform language – It can run on windows, Linux, Macintosh
etc. equally
• Expressive language – Less code to be written as it itself express the
purpose of the code.
• Completeness – Support wide rage of library
• Free & Open Source – Can be downloaded freely and source code
can be modify for improvement
Cons of Python
• Lesser libraries – as compared to other programming languages like
C++, java, .NET
• Slow language – as it is interpreted languages, it executes the
program slowly.
• Weak on Type-binding – It not pin point on use of a single variable for
different data type
Data types in Python
• We know that data types are nothing but the type of data we use to the variable,
method etc.
• We have following data types in Python.
1. Number
2. String
3. Boolean
4. List
5. Tuple
6. Set
7. Dictionary
Number
In Python we use number data type to store numeric value.
• Integer – Whole number without fraction parts ex: 1, 2 etc. Use 32 bits to store
value.
• Long integer – It store larger integer number. Use 32 bits to store value.
• Floating Point – It is a positive or negative real numbers with a
decimal point.
• Complex – Complex numbers are combination of a real and imaginary part.
Complex numbers are in the form of X+Yj, where X is a real part and
Y is imaginary part.
Input : a = complex(5) Output : (5+0j)
print(a)
String
• A string is a sequence of characters. In python we can create string
using single (' ') or double quotes (" ").Both are same in python.
Ex : - Input :
str='computer science’
print('str-', str) # print string
Output :
str- computer science
String Method
Method Description
Capitalize() Returns a copy of string with its first character as capita
Find() Returns the lowest index in the string
Isalnum() Returns true if the character in the string are alphanumeric
Isalpha() Returns true if the character in the string are alphabetic
Isdigit() Returns true if the character in the string are digit
Islower() Returns true if all the cased characters in the string are lowercase
Isupper() Returns true if all the cased characters in the string are uppercase
Title() Returns True if the string is in title case
Swapcase() Returns a copy of the string with uppercase character converted to lowercase and vice
versa
Partition() Splits the string at the first occurrence of argument
String Methods contd..
Method Description
Isspace() Returns true if there are only whitespace character in the string
Count() Returns the number of non-overlapping occurrence of substring in the given string
lstrip Returns a copy of the string with leading characters removed
rstrip Returns a copy of the string with trailing characters removed
Startswith() Returns true if string starts with the argument otherwise return false
Endswith() Returns true if string ends with the argument otherwise return false
Lower() Returns a copy of string converted to lowercase
Upper() Returns a copy of string converted to uppercase
Title() Returns a titlecase version of the string
Boolean
It is used to store two possible values either true or false.
e.g. a=“jnv"
b=str.isupper() # test if string contains upper case
print(b)
Output : False
LIST
List are collections of items and each item has its own index value.
List Methods
Method Description
Index() Returns the index of first matched item from the list
Append() Adds an item to the end of the list
Extend() Adds list at the end
Insert() Insert any item in between the list
Pop() Remove an item from the list
Remove() Remove the first occurrence of the given element
Clear() Remove all the items from the list
Count() Returns the count of the item that passes as argument
Reverse() Reverses the item of the list
Sort() Sort the item of the list, by default in increasing order
Tuples
• Tuples are list of value separated by comma ( , ).
• Tuples are Immutable which means values in the tuple can not
be changed.
• The data type in tuple can be any. Which means we can have
number and string in same tuple.
• Tuple is represented as : ( )
Example: 1) t1 = (1,2,3,4,5,6)
2) t2 = (‘A’ , ‘B’ , ‘C’)
3) t3 = (‘a’ , ‘b’ , 1,2,3,4,5,6)
Tuple Methods
Method Description
Len() Return the length of tuple
Max() Returns the element from the tuple having maximum value
Min() Returns the element from the tuple having minimum value
Index() Returns the index of an existing element of a tuple
Count() Returns the count of the member element / object in a given sequence( list/tuple)
Tuple() Constructor method, create tuple
Dictionary
• It is an unordered collection of items and each item consist of a key and a value.
e.g. dict = {'Subject': 'comp sc', 'class': '11’}
print(dict)
print ("Subject : ", dict['Subject’])
print ("class : ", dict.get('class’))
Output
{'Subject': 'comp sc', 'class': '11’}
Subject : comp sc class : 11
class : 11
Dictionary Method
Method Description
len() Returns length of the dictionary
clear() Remove all method from the dictionary
get() Get the item with the given key
has_keys To check the presence of given key in the dictionary
items() Return all the items of the dictionary
key() Return all the keys in the dictionary
value() Returns all the values from the dictionary in the form of list in no particular order
update() This will merge the key : value pairs from a new dictionary, adding or replacing as
needed
cmp Compare to dictionary based on their elements
List
• A list in python is represented by square bracket [].
• List is assigned to Variable
• The value inside a list can be changed.
example : (1) a = [1,2,3,4,5]
(2) b = [‘A’ , ‘B’ , ‘C’]
(3) c = [1,2, ’A’ , ‘B’ ]
Mutable and Immutable
Mutable data type can change
the value
• Dictionary
• List
Immutable data type can’t be
change value
• String
• Integer
• Tuples
• Booleans
• Floating Point
Arithmetic Operators
Operators are special symbols in Python that carry out arithmetic or logical
computation. The value that the operator operates on is called the operand.
Arithmetic operators Used for mathematical operation
Operator Meaning Example
+ Add two operands x + y +2
- Subtract right operand from the left x - y -2
* Multiply two operands x * y
/ Divide left operand by the right one x / y
% Modulus - remainder of the division x % y
// Floor division - division that results into whole number x // y
** Exponent - left operand raised to the power of right x**y
Comparison operators- Used to compare values
Operator Meaning Example
> Greater than - True if x is greater than y x > y
< Less that - True if x is less than y x < y
== Equal to - True if both operands are equal x == y
!= Not equal to - True if operands are not equal x != y
>= Greater than or equal to - True if left operand
is greater than or equal to the right x >= y
<= Less than or equal to - True if left operand
is less than or equal to the right x <= y
Logical Operator
Operator Meaning Example
and True if both the operands are true x and y
or True if either of the operands is true x or y
not True if operand is false not x
Operators Precedence
Operator~ + - Description
** Exponentiation (raise to the power)
~ + - Complement, unary plus and minus (method names for the last two are +@ and
-@)
* / % // Multiply, divide, modulo and floor division
+ - Addition and subtraction
>> << Right and left bitwise shift
& Bitwise 'AND'
^ | Bitwise exclusive `OR' and regular `OR'
<= < > >= Comparison operators
<> == != Equality operators
= %= /= //= -= += *= **= Assignment operators
is is not Identity operators
in not in Membership operators
not or and Logical operators
Python Function and Module
Python function :
• Function in Python are self
controlled piece of program
which perform a specific task.
• We can use in program whenever
needed by invoking them.
• Categories of python function:
1. Build in unction
2. Function defined in module
3. User defined function.
Python Module :
• It is a python file.
• It’s extension is .py
• Can be re-used in other
programs
• Can depend on other module
• Independent of grouping of code
and data
Statements Flow Control
Control statements are used to control the flow of execution depending
upon the specific condition.
1. Decision making statements
a. if statements
b. if-else statements
c. Nested if-else statement
2. Iteration statements (LOOPS)
a. While Loop
b. For Loop
c. Nested For Loops
3. Jump statements ( Break, continue, Pass )
If Statements
An if statement is a programming conditional statement that, if proved
true, performs a function or displays information.
Input Output
x=1
y=2
if(x==1 and y==2):
print(‘Matched')
Matched
if-else Statements
• If-else statement executes some code if the test expression is true
and some other code if the test expression is false.
Input Output
a=10
if(a < 100):
print(‘less than 100')
else:
print(‘more than equal
100')
less than 100
Nested if-else statement
The nested if...else statement allows you to check for multiple test
expressions and execute different codes for more than two conditions.
Input Output
num = float(input("Enter a
number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Enter a number: 4
Positive number
Iteration Statements (Loops)
While Loop
It is used to execute a block of statement as long as a given condition is true. And when the
condition become false, the control will come out of the loop. The condition is checked every time
at the beginning of the loop.
While – else
It is used to execute a block of statement as long as a given condition is true. And when the
condition become false, it execute else part of block of statements and come out of the loop.
Input (While ) Output
x = 1
while (x <= 4):
print(x)
x = x + 1
1
2
3
4
Input (While-else) Output
i = 0
while i < 4:
i += 1
print(i)
else:
print("Breakn")
1
2
3
4
Break
For Loop
• It is used to iterate over items of any sequence, such as a list or a
string.
• e.g.
• for i in range(3,5):
• print(i)
• Output
• 3
• 4
Continue Statement: It returns the control to the beginning of the loop
Break Statement: It brings control out of the loop.
Pass Statement: We use pass statement to write empty loops. Pass is also used for empty control statements,
function and classes.
Input Output
for letter in ‘rajeev':
if letter == 'e' or letter == ‘a':
continue
print( letter)
r
J
v
Input Output
for letter in 'rajeev':
if letter == 'a' or letter == 'j':
break
print('Current Letter :', letter)
Current Letter : a
for letter in 'rajeev':
pass
print('Last Letter :', letter)
Last Letter : v

More Related Content

PPS
As As
PPT
Countable And Uncountable Nouns Iii (Some And Any)
PPT
Future tenses
PPT
Adjectives, Comparatives And Superlatives 1
PPT
Simple Past Tense
PPT
Verbs of perception
PPTX
Nouns and Quantifiers
PPT
The Present Simple Tense
As As
Countable And Uncountable Nouns Iii (Some And Any)
Future tenses
Adjectives, Comparatives And Superlatives 1
Simple Past Tense
Verbs of perception
Nouns and Quantifiers
The Present Simple Tense

What's hot (20)

PPT
PPS
Future tense powerpoint
DOCX
Chemistry investigatory project
PPTX
Gerunds and Infinitives.pptx
PPTX
Adjectives of comparison & adverbs of comparison
PPTX
-ed and -ing adjectives
PPT
PDF
physics-project-final.pdf khdkkdhhdgdjgdhdh
PPT
Narrative tenses
PPTX
Adjectives ed-ing
PPTX
Teacher version: Look, Watch, See, Lesson 1 of Misused and Misunderstood Words
DOCX
Study of quantity of caesin present in different samples of milk
PPTX
About rate of fermention
DOCX
Physics investigatory project by pinaki bandyopadhyay
PPTX
6 can can't
PPTX
Possesive adjectives
PPT
Compound nouns
PDF
Chemistryprojectoncaseininmik 170207030628
PPT
This is my (face parts)
DOCX
Comparison as-as
Future tense powerpoint
Chemistry investigatory project
Gerunds and Infinitives.pptx
Adjectives of comparison & adverbs of comparison
-ed and -ing adjectives
physics-project-final.pdf khdkkdhhdgdjgdhdh
Narrative tenses
Adjectives ed-ing
Teacher version: Look, Watch, See, Lesson 1 of Misused and Misunderstood Words
Study of quantity of caesin present in different samples of milk
About rate of fermention
Physics investigatory project by pinaki bandyopadhyay
6 can can't
Possesive adjectives
Compound nouns
Chemistryprojectoncaseininmik 170207030628
This is my (face parts)
Comparison as-as
Ad

Similar to Python Revision Tour.pptx class 12 python notes (20)

PPTX
Python bible
PPTX
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
PDF
Python cheatsheat.pdf
PDF
Data Handling_XI- All details for cbse board grade 11
PPTX
Python PPT2
PDF
Data Handling_XI_Finall for grade 11 cbse board
PDF
Python Objects
PPTX
Parts of python programming language
PPTX
Learn more about the concepts of Data Types in Python
PPTX
funadamentals of python programming language (right from scratch)
PPTX
Programming Basics.pptx
PDF
Python Basics it will teach you about data types
PPTX
Introduction_to_Python_operators_datatypes.pptx
PDF
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
PDF
ppt_pspp.pdf
PPTX
PPTX
Pythonppt28 11-18
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
PPTX
python presentation.pptx
PPTX
Python Workshop
Python bible
CLASS-11 & 12 ICT PPT PYTHON PROGRAMMING.pptx
Python cheatsheat.pdf
Data Handling_XI- All details for cbse board grade 11
Python PPT2
Data Handling_XI_Finall for grade 11 cbse board
Python Objects
Parts of python programming language
Learn more about the concepts of Data Types in Python
funadamentals of python programming language (right from scratch)
Programming Basics.pptx
Python Basics it will teach you about data types
Introduction_to_Python_operators_datatypes.pptx
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
ppt_pspp.pdf
Pythonppt28 11-18
FUNDAMENTALS OF PYTHON LANGUAGE
python presentation.pptx
Python Workshop
Ad

Recently uploaded (20)

PDF
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
PPTX
climate change of delhi impacts on climate and there effects
PDF
Teacher's Day Quiz 2025
PPTX
Environmental Sciences and Sustainability Chapter 2
PPTX
CHF refers to the condition wherein heart unable to pump a sufficient amount ...
PDF
Jana-Ojana Finals 2025 - School Quiz by Pragya - UEMK Quiz Club
PPSX
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
PDF
GSA-Past-Papers-2010-2024-2.pdf CSS examination
PDF
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
PDF
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
PDF
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
PDF
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
PDF
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
PPTX
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
PPTX
macro complete discussion with given activities
DOCX
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
PDF
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PDF
New_Round_Up_6_SB.pdf download for free, easy to learn
PPTX
Juvenile delinquency-Crim Research day 3x
HSE 2022-2023.pdf الصحه والسلامه هندسه نفط
climate change of delhi impacts on climate and there effects
Teacher's Day Quiz 2025
Environmental Sciences and Sustainability Chapter 2
CHF refers to the condition wherein heart unable to pump a sufficient amount ...
Jana-Ojana Finals 2025 - School Quiz by Pragya - UEMK Quiz Club
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
GSA-Past-Papers-2010-2024-2.pdf CSS examination
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
BSc-Zoology-02Sem-DrVijay-Comparative anatomy of vertebrates.pdf
Kalaari-SaaS-Founder-Playbook-2024-Edition-.pdf
WHAT NURSES SAY_ COMMUNICATION BEHAVIORS ASSOCIATED WITH THE COMP.pdf
Jana Ojana 2025 Prelims - School Quiz by Pragya - UEMK Quiz Club
Unit1_Kumod_deeplearning.pptx DEEP LEARNING
macro complete discussion with given activities
HELMET DETECTION AND BIOMETRIC BASED VEHICLESECURITY USING MACHINE LEARNING.docx
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
New_Round_Up_6_SB.pdf download for free, easy to learn
Juvenile delinquency-Crim Research day 3x

Python Revision Tour.pptx class 12 python notes

  • 2. Introduction Python revision Tour- 1 • Introduction to Python • Working with Python • Data types , Operations • Python Functions, Modules • Flow of execution • Statement flow control Python revision Tour- 2 • Sting in python • List in python • Tuple in python • Dictionary in python
  • 3. Python used as general purpose, high level programming language. Developed by Guido van Rossum in 1991. Pros of Python : • Easy to use – Due to simple syntax rule • Interpreted language – Code execution & interpretation line by line • Cross-platform language – It can run on windows, Linux, Macintosh etc. equally • Expressive language – Less code to be written as it itself express the purpose of the code. • Completeness – Support wide rage of library • Free & Open Source – Can be downloaded freely and source code can be modify for improvement
  • 4. Cons of Python • Lesser libraries – as compared to other programming languages like C++, java, .NET • Slow language – as it is interpreted languages, it executes the program slowly. • Weak on Type-binding – It not pin point on use of a single variable for different data type
  • 5. Data types in Python • We know that data types are nothing but the type of data we use to the variable, method etc. • We have following data types in Python. 1. Number 2. String 3. Boolean 4. List 5. Tuple 6. Set 7. Dictionary
  • 6. Number In Python we use number data type to store numeric value. • Integer – Whole number without fraction parts ex: 1, 2 etc. Use 32 bits to store value. • Long integer – It store larger integer number. Use 32 bits to store value. • Floating Point – It is a positive or negative real numbers with a decimal point. • Complex – Complex numbers are combination of a real and imaginary part. Complex numbers are in the form of X+Yj, where X is a real part and Y is imaginary part. Input : a = complex(5) Output : (5+0j) print(a)
  • 7. String • A string is a sequence of characters. In python we can create string using single (' ') or double quotes (" ").Both are same in python. Ex : - Input : str='computer science’ print('str-', str) # print string Output : str- computer science
  • 8. String Method Method Description Capitalize() Returns a copy of string with its first character as capita Find() Returns the lowest index in the string Isalnum() Returns true if the character in the string are alphanumeric Isalpha() Returns true if the character in the string are alphabetic Isdigit() Returns true if the character in the string are digit Islower() Returns true if all the cased characters in the string are lowercase Isupper() Returns true if all the cased characters in the string are uppercase Title() Returns True if the string is in title case Swapcase() Returns a copy of the string with uppercase character converted to lowercase and vice versa Partition() Splits the string at the first occurrence of argument
  • 9. String Methods contd.. Method Description Isspace() Returns true if there are only whitespace character in the string Count() Returns the number of non-overlapping occurrence of substring in the given string lstrip Returns a copy of the string with leading characters removed rstrip Returns a copy of the string with trailing characters removed Startswith() Returns true if string starts with the argument otherwise return false Endswith() Returns true if string ends with the argument otherwise return false Lower() Returns a copy of string converted to lowercase Upper() Returns a copy of string converted to uppercase Title() Returns a titlecase version of the string
  • 10. Boolean It is used to store two possible values either true or false. e.g. a=“jnv" b=str.isupper() # test if string contains upper case print(b) Output : False LIST List are collections of items and each item has its own index value.
  • 11. List Methods Method Description Index() Returns the index of first matched item from the list Append() Adds an item to the end of the list Extend() Adds list at the end Insert() Insert any item in between the list Pop() Remove an item from the list Remove() Remove the first occurrence of the given element Clear() Remove all the items from the list Count() Returns the count of the item that passes as argument Reverse() Reverses the item of the list Sort() Sort the item of the list, by default in increasing order
  • 12. Tuples • Tuples are list of value separated by comma ( , ). • Tuples are Immutable which means values in the tuple can not be changed. • The data type in tuple can be any. Which means we can have number and string in same tuple. • Tuple is represented as : ( ) Example: 1) t1 = (1,2,3,4,5,6) 2) t2 = (‘A’ , ‘B’ , ‘C’) 3) t3 = (‘a’ , ‘b’ , 1,2,3,4,5,6)
  • 13. Tuple Methods Method Description Len() Return the length of tuple Max() Returns the element from the tuple having maximum value Min() Returns the element from the tuple having minimum value Index() Returns the index of an existing element of a tuple Count() Returns the count of the member element / object in a given sequence( list/tuple) Tuple() Constructor method, create tuple
  • 14. Dictionary • It is an unordered collection of items and each item consist of a key and a value. e.g. dict = {'Subject': 'comp sc', 'class': '11’} print(dict) print ("Subject : ", dict['Subject’]) print ("class : ", dict.get('class’)) Output {'Subject': 'comp sc', 'class': '11’} Subject : comp sc class : 11 class : 11
  • 15. Dictionary Method Method Description len() Returns length of the dictionary clear() Remove all method from the dictionary get() Get the item with the given key has_keys To check the presence of given key in the dictionary items() Return all the items of the dictionary key() Return all the keys in the dictionary value() Returns all the values from the dictionary in the form of list in no particular order update() This will merge the key : value pairs from a new dictionary, adding or replacing as needed cmp Compare to dictionary based on their elements
  • 16. List • A list in python is represented by square bracket []. • List is assigned to Variable • The value inside a list can be changed. example : (1) a = [1,2,3,4,5] (2) b = [‘A’ , ‘B’ , ‘C’] (3) c = [1,2, ’A’ , ‘B’ ]
  • 17. Mutable and Immutable Mutable data type can change the value • Dictionary • List Immutable data type can’t be change value • String • Integer • Tuples • Booleans • Floating Point
  • 18. Arithmetic Operators Operators are special symbols in Python that carry out arithmetic or logical computation. The value that the operator operates on is called the operand. Arithmetic operators Used for mathematical operation Operator Meaning Example + Add two operands x + y +2 - Subtract right operand from the left x - y -2 * Multiply two operands x * y / Divide left operand by the right one x / y % Modulus - remainder of the division x % y // Floor division - division that results into whole number x // y ** Exponent - left operand raised to the power of right x**y
  • 19. Comparison operators- Used to compare values Operator Meaning Example > Greater than - True if x is greater than y x > y < Less that - True if x is less than y x < y == Equal to - True if both operands are equal x == y != Not equal to - True if operands are not equal x != y >= Greater than or equal to - True if left operand is greater than or equal to the right x >= y <= Less than or equal to - True if left operand is less than or equal to the right x <= y
  • 20. Logical Operator Operator Meaning Example and True if both the operands are true x and y or True if either of the operands is true x or y not True if operand is false not x
  • 21. Operators Precedence Operator~ + - Description ** Exponentiation (raise to the power) ~ + - Complement, unary plus and minus (method names for the last two are +@ and -@) * / % // Multiply, divide, modulo and floor division + - Addition and subtraction >> << Right and left bitwise shift & Bitwise 'AND' ^ | Bitwise exclusive `OR' and regular `OR' <= < > >= Comparison operators <> == != Equality operators = %= /= //= -= += *= **= Assignment operators is is not Identity operators in not in Membership operators not or and Logical operators
  • 22. Python Function and Module Python function : • Function in Python are self controlled piece of program which perform a specific task. • We can use in program whenever needed by invoking them. • Categories of python function: 1. Build in unction 2. Function defined in module 3. User defined function. Python Module : • It is a python file. • It’s extension is .py • Can be re-used in other programs • Can depend on other module • Independent of grouping of code and data
  • 23. Statements Flow Control Control statements are used to control the flow of execution depending upon the specific condition. 1. Decision making statements a. if statements b. if-else statements c. Nested if-else statement 2. Iteration statements (LOOPS) a. While Loop b. For Loop c. Nested For Loops 3. Jump statements ( Break, continue, Pass )
  • 24. If Statements An if statement is a programming conditional statement that, if proved true, performs a function or displays information. Input Output x=1 y=2 if(x==1 and y==2): print(‘Matched') Matched
  • 25. if-else Statements • If-else statement executes some code if the test expression is true and some other code if the test expression is false. Input Output a=10 if(a < 100): print(‘less than 100') else: print(‘more than equal 100') less than 100
  • 26. Nested if-else statement The nested if...else statement allows you to check for multiple test expressions and execute different codes for more than two conditions. Input Output num = float(input("Enter a number: ")) if num >= 0: if num == 0: print("Zero") else: print("Positive number") else: print("Negative number") Enter a number: 4 Positive number
  • 27. Iteration Statements (Loops) While Loop It is used to execute a block of statement as long as a given condition is true. And when the condition become false, the control will come out of the loop. The condition is checked every time at the beginning of the loop. While – else It is used to execute a block of statement as long as a given condition is true. And when the condition become false, it execute else part of block of statements and come out of the loop. Input (While ) Output x = 1 while (x <= 4): print(x) x = x + 1 1 2 3 4 Input (While-else) Output i = 0 while i < 4: i += 1 print(i) else: print("Breakn") 1 2 3 4 Break
  • 28. For Loop • It is used to iterate over items of any sequence, such as a list or a string. • e.g. • for i in range(3,5): • print(i) • Output • 3 • 4
  • 29. Continue Statement: It returns the control to the beginning of the loop Break Statement: It brings control out of the loop. Pass Statement: We use pass statement to write empty loops. Pass is also used for empty control statements, function and classes. Input Output for letter in ‘rajeev': if letter == 'e' or letter == ‘a': continue print( letter) r J v Input Output for letter in 'rajeev': if letter == 'a' or letter == 'j': break print('Current Letter :', letter) Current Letter : a for letter in 'rajeev': pass print('Last Letter :', letter) Last Letter : v