SlideShare a Scribd company logo
UNIT III
CONTROL FLOW, FUNCTIONS
CONTROL FLOW, FUNCTIONS
 Conditionals: Boolean values and operators,
conditional (if), alternative (if-else), chained
conditional (if-elif-else);
 Iteration: state, while, for, break, continue,
pass;
 Fruitful functions: return values, parameters,
 scope: local and global, composition, recursion;
 Strings: string slices, immutability, string functions
and methods, string module; Lists as arrays.
 Illustrative programs: square root, gcd,
exponentiation, sum the array of numbers, linear
search, binary search.
BOOLEAN VALUES:
Boolean:
 Boolean data type have two values. They
are 0 and 1.
 0 represents False
 1 represents True
 True and False are keyword.
Example:
>>> 3==5
False
>>> 6==6
True
>>> True+True
2
>>> False+True
1
>>> False*True
0
OPERATORS:
 Operators are the constructs which can
manipulate the value of operands.
 Consider the expression 4 + 5 = 9. Here,
4 and 5 are called operands and + is
called operator.
Types of Operators:
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Assignment Operators
4. Logical Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Arithmetic operators:
• They are used to perform mathematical operations like
addition, subtraction, multiplication etc.
Operator Description Example
a=10,b=20
+ Addition Adds values on either side of the
operator.
a + b = 30
-
Subtraction
Subtracts right hand operand from left
hand operand.
a – b = -10
Operator Description Example
a=10,b=20
+ Addition Adds values on either side of the
operator.
a + b = 30
- Subtraction Subtracts right hand operand from
left hand operand.
a – b = -10
* Multiplication Multiplies values on either side of
the operator
a * b = 200
/ Division Divides left hand operand by right
hand operand
b / a = 2
Operator Description Example
a=10,b=20
% Modulus Divides left hand operand by right
hand operand and returns
remainder
b % a = 0
** Exponent Performs exponential (power)
calculation on operators
a**b =10 to
the
power 20
// Floor Division - The division of
operands where the result is the
quotient in which the digits after the
decimal point are removed
5//2=2
Comparison (Relational) Operators:
• Comparison operators are used to compare values.
• It either returns True or False according to the condition.
Operator Description Example
a=10,b=20
== If the values of two operands are equal,
then the condition becomes true.
(a == b) is
not true.
!= If values of two operands are not equal,
then condition becomes true.
a – b = -10(a!
=b) is true
Operator Description Example
a=10,b=20
> If the value of left operand is greater than the
value of right operand, then condition
becomes true.
(a > b) is not
true.
< If the value of left operand is less than the
value of right operand, then condition
becomes true.
(a < b) is true.
>= If the value of left operand is greater than or
equal to the value of right operand, then
condition becomes true.
(a >= b) is not
true.
<= If the value of left operand is less than or
equal to the value of right operand, then
condition becomes true.
(a <= b) is
true.
Assignment Operators:
Operator Description Example
= Assigns values from right side
operands to left side operand
c = a + b assigns
value of a + b into
c
+= Add AND It adds right operand to the left
operand and assign the result to
left operand
c += a is
equivalent
to c = c + a
-= Subtract
AND
It subtracts right operand from the
left operand and assign the result
to left operand
c -= a is
equivalent
to c = c - a
Operator Description Example
*= Multiply
AND
It multiplies right operand with
the left operand and assign the
result to left operand
c *= a is
equivalent to c
= c * a
/= Divide
AND
It divides left operand with the
right operand and assign the
result to left operand
c /= a is
equivalent to c
= c / ac /= a is
equivalent to c
= c / a
Operator Description Example
%= Modulus
AND
It takes modulus using two operands
and assign the result to left operand
c %= a is
equivalent to c = c
% a
**= Exponent
AND
Performs exponential (power)
calculation on operators and assign
value to the left operand
c **= a is
equivalent to c = c
** a
//= Floor Division It performs floor division on
operators and assign value to the left
operand
c //= a is
equivalent to c =
c // a
Logical Operators:
Logical operators are and, or, not operators.
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 (complements
the operand
not x
Bitwise Operators:
• Let x = 10 (0000 1010 in binary) and y = 4 (0000
0100 in binary)
Operator Meaning Example
& Bitwise AND x & y = 0 (0000 0000)
I Bitwise OR x i y = 14 (0000 1110)
- Bitwise NOT -x = -11 (1111 0101)
^ Bitwise XOR x ^ y = 14 (0000 1110)
>> Bitwise right shift x>> 2 = 2 (0000 0010)
<< Bitwise left shift x<< 2 = 40 (0010 1000)
Membership Operators:
Evaluates to find a value or a variable is in the
specified sequence of string, list, tuple,
dictionary or not.
To check particular element is available in the
list or not.
Operators are in and not in.
Membership Operators:
Operator Meaning Example
in True if value/variable is
found in the sequence
5 in x
not in True if value/variable is
not found in the sequence
5 in not x
Example:
x=[5,3,6,4,1]
>>> 5 in x
True
>>> 5 not in x
False
Identity Operators:
• They are used to check if two values (or variables)
are located on the same part of the memory.
Operator Meaning Example
Is True if the operands are
identical (refer to the same
object)
X is true
Is not True if the operands are
not identical (do not refer
to the same object)
X is not true.
Example:
x = 5
y = 5
a = 'Hello'
b = 'Hello‘
print(x is not y) // False
print(a is b)//True
CONDITIONALS
 Conditional if
 Alternative if… else
 Chained if…elif…else
 Nested if….else
Conditional (if):
• conditional (if) is used to test a condition, if the
condition is true the statements inside if will be
executed.
Syntax:
if (confition 1) :
statement 1

More Related Content

Similar to Python notes for students to develop and learn (20)

Python : basic operators
Python : basic operators
S.M. Salaquzzaman
 
Python basic operators
Python basic operators
Learnbay Datascience
 
Python Lec-6 Operatorguijjjjuugggggs.pptx
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
ramireddyobulakondar
 
Java script session 4
Java script session 4
Saif Ullah Dar
 
Python Basic Operators
Python Basic Operators
Soba Arjun
 
Report on c
Report on c
jasmeen kr
 
Python operators
Python operators
SaurabhUpadhyay73
 
Operators1.pptx
Operators1.pptx
HARSHSHARMA840
 
Session03 operators
Session03 operators
HarithaRanasinghe
 
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
arshadfarhad08
 
Operators and it's type
Operators and it's type
Asheesh kushwaha
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Step by step python(week2)
Step by step python(week2)
Abhishek Jaiswal
 
Logical Operators C/C++ language Programming
Logical Operators C/C++ language Programming
Nawab Developers
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Operators in C/C++
Operators in C/C++
Shobi P P
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
NagarathnaRajur2
 
Python Lec-6 Operatorguijjjjuugggggs.pptx
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
Operators in Python Arithmetic Operators
Operators in Python Arithmetic Operators
ramireddyobulakondar
 
Python Basic Operators
Python Basic Operators
Soba Arjun
 
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
Lecture - Operators in C++ (Book: Tony Gaddis).pptx
arshadfarhad08
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Step by step python(week2)
Step by step python(week2)
Abhishek Jaiswal
 
Logical Operators C/C++ language Programming
Logical Operators C/C++ language Programming
Nawab Developers
 
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Programming | JNTUK | UNIT 1 | Lecture 5
FabMinds
 
Operators in C/C++
Operators in C/C++
Shobi P P
 
Python_Module_3_AFkkkkV_Operators-1.pptx
Python_Module_3_AFkkkkV_Operators-1.pptx
tissot723
 
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
NagarathnaRajur2
 

Recently uploaded (20)

Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
LDMMIA Spring Ending Guest Grad Student News
LDMMIA Spring Ending Guest Grad Student News
LDM & Mia eStudios
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Ad

Python notes for students to develop and learn

  • 2. CONTROL FLOW, FUNCTIONS  Conditionals: Boolean values and operators, conditional (if), alternative (if-else), chained conditional (if-elif-else);  Iteration: state, while, for, break, continue, pass;
  • 3.  Fruitful functions: return values, parameters,  scope: local and global, composition, recursion;  Strings: string slices, immutability, string functions and methods, string module; Lists as arrays.  Illustrative programs: square root, gcd, exponentiation, sum the array of numbers, linear search, binary search.
  • 4. BOOLEAN VALUES: Boolean:  Boolean data type have two values. They are 0 and 1.  0 represents False  1 represents True  True and False are keyword.
  • 5. Example: >>> 3==5 False >>> 6==6 True >>> True+True 2 >>> False+True 1 >>> False*True 0
  • 6. OPERATORS:  Operators are the constructs which can manipulate the value of operands.  Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator.
  • 7. Types of Operators: 1. Arithmetic Operators 2. Comparison (Relational) Operators 3. Assignment Operators 4. Logical Operators 5. Bitwise Operators 6. Membership Operators 7. Identity Operators
  • 8. Arithmetic operators: • They are used to perform mathematical operations like addition, subtraction, multiplication etc. Operator Description Example a=10,b=20 + Addition Adds values on either side of the operator. a + b = 30 - Subtraction Subtracts right hand operand from left hand operand. a – b = -10
  • 9. Operator Description Example a=10,b=20 + Addition Adds values on either side of the operator. a + b = 30 - Subtraction Subtracts right hand operand from left hand operand. a – b = -10 * Multiplication Multiplies values on either side of the operator a * b = 200 / Division Divides left hand operand by right hand operand b / a = 2
  • 10. Operator Description Example a=10,b=20 % Modulus Divides left hand operand by right hand operand and returns remainder b % a = 0 ** Exponent Performs exponential (power) calculation on operators a**b =10 to the power 20 // Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed 5//2=2
  • 11. Comparison (Relational) Operators: • Comparison operators are used to compare values. • It either returns True or False according to the condition. Operator Description Example a=10,b=20 == If the values of two operands are equal, then the condition becomes true. (a == b) is not true. != If values of two operands are not equal, then condition becomes true. a – b = -10(a! =b) is true
  • 12. Operator Description Example a=10,b=20 > If the value of left operand is greater than the value of right operand, then condition becomes true. (a > b) is not true. < If the value of left operand is less than the value of right operand, then condition becomes true. (a < b) is true. >= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. (a >= b) is not true. <= If the value of left operand is less than or equal to the value of right operand, then condition becomes true. (a <= b) is true.
  • 13. Assignment Operators: Operator Description Example = Assigns values from right side operands to left side operand c = a + b assigns value of a + b into c += Add AND It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c - a
  • 14. Operator Description Example *= Multiply AND It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a /= Divide AND It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a
  • 15. Operator Description Example %= Modulus AND It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent AND Performs exponential (power) calculation on operators and assign value to the left operand c **= a is equivalent to c = c ** a //= Floor Division It performs floor division on operators and assign value to the left operand c //= a is equivalent to c = c // a
  • 16. Logical Operators: Logical operators are and, or, not operators. 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 (complements the operand not x
  • 17. Bitwise Operators: • Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary) Operator Meaning Example & Bitwise AND x & y = 0 (0000 0000) I Bitwise OR x i y = 14 (0000 1110) - Bitwise NOT -x = -11 (1111 0101) ^ Bitwise XOR x ^ y = 14 (0000 1110) >> Bitwise right shift x>> 2 = 2 (0000 0010) << Bitwise left shift x<< 2 = 40 (0010 1000)
  • 18. Membership Operators: Evaluates to find a value or a variable is in the specified sequence of string, list, tuple, dictionary or not. To check particular element is available in the list or not. Operators are in and not in.
  • 19. Membership Operators: Operator Meaning Example in True if value/variable is found in the sequence 5 in x not in True if value/variable is not found in the sequence 5 in not x
  • 20. Example: x=[5,3,6,4,1] >>> 5 in x True >>> 5 not in x False
  • 21. Identity Operators: • They are used to check if two values (or variables) are located on the same part of the memory. Operator Meaning Example Is True if the operands are identical (refer to the same object) X is true Is not True if the operands are not identical (do not refer to the same object) X is not true.
  • 22. Example: x = 5 y = 5 a = 'Hello' b = 'Hello‘ print(x is not y) // False print(a is b)//True
  • 23. CONDITIONALS  Conditional if  Alternative if… else  Chained if…elif…else  Nested if….else
  • 24. Conditional (if): • conditional (if) is used to test a condition, if the condition is true the statements inside if will be executed. Syntax: if (confition 1) : statement 1