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
Ad

More Related Content

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

23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf
RajeshThanikachalam
 
23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
RajeshThanikachalam
 
Operator 04 (js)
Operator 04 (js)Operator 04 (js)
Operator 04 (js)
AbhishekMondal42
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
divyalakshmi77
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
Megha Sharma
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
ErnieAcuna
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLESPPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
Operators Concept in Python-N.Kavitha.pptx
Operators Concept in Python-N.Kavitha.pptxOperators Concept in Python-N.Kavitha.pptx
Operators Concept in Python-N.Kavitha.pptx
Kavitha713564
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
Jaya Kumari
 
Types of Operators in C
Types of Operators in CTypes of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
Prof Ansari
 
07 ruby operators
07 ruby operators07 ruby operators
07 ruby operators
Walker Maidana
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
Asheesh kushwaha
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
Shobi P P
 
Operators
OperatorsOperators
Operators
Devi Pradeep Podugu
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 
23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python programming - UNIT 3.pdf
RajeshThanikachalam
 
23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf23CSC101T PSPP python program - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
RajeshThanikachalam
 
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
prasadmutkule1
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
divyalakshmi77
 
Conditional and special operators
Conditional and special operatorsConditional and special operators
Conditional and special operators
Megha Sharma
 
python operators.ppt
python operators.pptpython operators.ppt
python operators.ppt
ErnieAcuna
 
04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching04. Ruby Operators Slides - Ruby Core Teaching
04. Ruby Operators Slides - Ruby Core Teaching
quanhoangd129
 
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLESPPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
PPT ON JAVA AND UNDERSTANDING JAVA'S PRINCIPLES
merabapudc
 
Operators Concept in Python-N.Kavitha.pptx
Operators Concept in Python-N.Kavitha.pptxOperators Concept in Python-N.Kavitha.pptx
Operators Concept in Python-N.Kavitha.pptx
Kavitha713564
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
Jaya Kumari
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
Prof Ansari
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
savitamhaske
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
Shobi P P
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
Himanshu Kaushik
 
C++ revision add on till now
C++ revision add on till nowC++ revision add on till now
C++ revision add on till now
AmAn Singh
 

Recently uploaded (20)

Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
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
  翻译: