SlideShare a Scribd company logo
Operators in Python
Python class 2
Complex Numbers
form a + bJ, where a and b are floats and j represents the square root of -1 (which is
an imaginary number).
x= complex(a,b)
abs(x)
x.real x.imag ,x.conjugate(),x.abs()
Not used much in Python programming
Code: https://repl.it/H5bg/2
Operators
Special symbols that represent computations like addition
and multiplication. The values the operator is applied to are
called operands.
a+b=c { a and b is operand and + is operator}
Types of Operators:
Arithmetic Operators
Comparison (Relational) Operators
Logical Operators
Bitwise Operators
Arithmetic Operators
+ - * / // % **
+ and - can be used as unary and binary operator. {unary means identity ).Examples:
complex(2,3) * complex(2,3),7+True,8-False
4/9, -4/9, -5--5, 7//9, -7//9 , -7.0//2, -7.0/2
“Abc” * 2, “Abc” * -2, “Abc” *0, “Abc”* True, 7+True,8.5 +True
math.floor(-7.5) ,math.ceil(-8.2), math.ceil(-1), 4**2 ,2**1.2
% operator and modular division of -ve number.
Code Exercise: https://repl.it/H5c4/5
https://www.python.org/dev/peps/pep-0238/ ----> Proposal to change division operator
Relational Operators
== != < > <= >= is is
not
in
Difference between is and ==
a = ’ abc ’
b = a
c = input ( ’ Enter String : ’)
Relational Operators
An is expression evaluates to True if two variables point to the same (identical)
object.
An == expression evaluates to True if the objects referred to by the variables are
equal (have the same contents).
< and > for two strings
ord(‘a’) to find ASCII
Logical Operators
Discuss the truth table: for booleans.
And operator: first evaluates its left operand,if false,result is left else right operand
Or : evaluates its left operand,if True,the result returned is the value of the left
operand; otherwise, right operand.
Not operator can only be used as unary operator.
True is not True
Bit–wise Operators
Bitwise operator works on bits and performs bit by bit operation.
a = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100
a|b = 0011 1101
a^b = 0011 0001
~a = 1100 0011
Bit–wise Operators
Left Shift << and right Shift >>
Operator Precedence :
PEMDAS : Parentheses,Exponentiation,Multiplication.Division,Addition,Substraction
* And / has same precedence. + and - has same precedence.
Operator with same precedence are evaluated from left to right.
Control Flows
IF :Used to check a condition: if the condition is true, run a block of statements
(called the if-block), else process another block of statements (called the else-
block). The else clause is optional.
elif:
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Coding Exercises
1. Input the number from keyboard and check if number is positive or negative.
Modify the code and print “Number is Zero” if number is 0.
2. Decide a number and take guesses from the user and check if it is the number
that we have.
3. Python Program to check if number is even or odd.
// And %
7 3 2 1
-7 3 -3 2
7 -3 -3 -2
-7 -3 2 -1
Ad

Recommended

Python operators
Python operators
SaurabhUpadhyay73
 
Python Operators
Python Operators
Adheetha O. V
 
Operators in Python
Operators in Python
Anusuya123
 
Operators in python
Operators in python
eShikshak
 
Operators in python
Operators in python
deepalishinkar1
 
Python : basic operators
Python : basic operators
S.M. Salaquzzaman
 
Operators in python
Operators in python
Prabhakaran V M
 
Python Basic Operators
Python Basic Operators
Soba Arjun
 
Operators
Operators
Kamran
 
Operator.ppt
Operator.ppt
Darshan Patel
 
Operators and Expressions
Operators and Expressions
Munazza-Mah-Jabeen
 
Python operators
Python operators
nuripatidar
 
Operators in C & C++ Language
Operators in C & C++ Language
PreSolutions Softwares
 
Basic c operators
Basic c operators
dishti7
 
C Sharp Jn (2)
C Sharp Jn (2)
guest58c84c
 
Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Operators in c++
Operators in c++
ABHIJITPATRA23
 
Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
Expressions in c++
Expressions in c++
zeeshan turi
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
C – operators and expressions
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Operation and expression in c++
Operation and expression in c++
Online
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming
Kamal Acharya
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
Deepak Singh
 
Operators
Operators
jayesh30sikchi
 
Types of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
Java basic operators
Java basic operators
Emmanuel Alimpolos
 
Java basic operators
Java basic operators
Emmanuel Alimpolos
 

More Related Content

What's hot (17)

Operators
Operators
Kamran
 
Operator.ppt
Operator.ppt
Darshan Patel
 
Operators and Expressions
Operators and Expressions
Munazza-Mah-Jabeen
 
Python operators
Python operators
nuripatidar
 
Operators in C & C++ Language
Operators in C & C++ Language
PreSolutions Softwares
 
Basic c operators
Basic c operators
dishti7
 
C Sharp Jn (2)
C Sharp Jn (2)
guest58c84c
 
Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Operators in c++
Operators in c++
ABHIJITPATRA23
 
Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
Expressions in c++
Expressions in c++
zeeshan turi
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
C – operators and expressions
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Operation and expression in c++
Operation and expression in c++
Online
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming
Kamal Acharya
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
Deepak Singh
 
Operators
Operators
Kamran
 
Python operators
Python operators
nuripatidar
 
Basic c operators
Basic c operators
dishti7
 
Operator & Expression in c++
Operator & Expression in c++
bajiajugal
 
Operators and expressions in C++
Operators and expressions in C++
Neeru Mittal
 
Expressions in c++
Expressions in c++
zeeshan turi
 
CBSE Class XI :- Operators in C++
CBSE Class XI :- Operators in C++
Pranav Ghildiyal
 
Operators and Expressions in C++
Operators and Expressions in C++
Praveen M Jigajinni
 
Operation and expression in c++
Operation and expression in c++
Online
 
Expression and Operartor In C Programming
Expression and Operartor In C Programming
Kamal Acharya
 
Chapter 5 - Operators in C++
Chapter 5 - Operators in C++
Deepak Singh
 

Similar to Python Training in Bangalore | Python Operators | Learnbay.in (20)

Operators
Operators
jayesh30sikchi
 
Types of Operators in C
Types of Operators in C
Thesis Scientist Private Limited
 
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
hlukj6;lukm,t.mnjhgjukryopkiu;lyk y2.ppt
PraveenaFppt
 
Java basic operators
Java basic operators
Emmanuel Alimpolos
 
Java basic operators
Java basic operators
Emmanuel Alimpolos
 
Python programming language introduction unit
Python programming language introduction unit
michaelaaron25322
 
Py-Slides-2 (1).ppt
Py-Slides-2 (1).ppt
KalaiVani395886
 
Py-Slides-2.ppt
Py-Slides-2.ppt
TejaValmiki
 
Py-Slides-2.ppt
Py-Slides-2.ppt
AllanGuevarra1
 
Python notes for students to develop and learn
Python notes for students to develop and learn
kavithaadhilakshmi
 
python operators.ppt
python operators.ppt
ErnieAcuna
 
Coper in C
Coper in C
thirumalaikumar3
 
Report on c
Report on c
jasmeen kr
 
Python tutorials for beginners | IQ Online Training
Python tutorials for beginners | IQ Online Training
Rahul Tandale
 
C Operators
C Operators
Yash Modi
 
Python Lec-6 Operatorguijjjjuugggggs.pptx
Python Lec-6 Operatorguijjjjuugggggs.pptx
ks812227
 
C Sharp Jn (2)
C Sharp Jn (2)
jahanullah
 
Operators
Operators
Devi Pradeep Podugu
 
Java 2
Java 2
Preethi Nambiar
 
Java - Operators
Java - Operators
Preethi Nambiar
 
Ad

Recently uploaded (20)

SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 6-14-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
LDMMIA Practitioner Level Orientation Updates
LDMMIA Practitioner Level Orientation Updates
LDM & Mia eStudios
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
University of Ghana Cracks Down on Misconduct: Over 100 Students Sanctioned
Kweku Zurek
 
How to Manage Different Customer Addresses in Odoo 18 Accounting
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
LDMMIA Practitioner Level Orientation Updates
LDMMIA Practitioner Level Orientation Updates
LDM & Mia eStudios
 
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
Assisting Individuals and Families to Promote and Maintain Health – Unit 7 | ...
RAKESH SAJJAN
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
Communicable Diseases and National Health Programs – Unit 9 | B.Sc Nursing 5t...
RAKESH SAJJAN
 
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
ENGLISH_Q1_W1 PowerPoint grade 3 quarter 1 week 1
jutaydeonne
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
Ad

Python Training in Bangalore | Python Operators | Learnbay.in

  • 2. Complex Numbers form a + bJ, where a and b are floats and j represents the square root of -1 (which is an imaginary number). x= complex(a,b) abs(x) x.real x.imag ,x.conjugate(),x.abs() Not used much in Python programming Code: https://repl.it/H5bg/2
  • 3. Operators Special symbols that represent computations like addition and multiplication. The values the operator is applied to are called operands. a+b=c { a and b is operand and + is operator} Types of Operators: Arithmetic Operators Comparison (Relational) Operators Logical Operators Bitwise Operators
  • 4. Arithmetic Operators + - * / // % ** + and - can be used as unary and binary operator. {unary means identity ).Examples: complex(2,3) * complex(2,3),7+True,8-False 4/9, -4/9, -5--5, 7//9, -7//9 , -7.0//2, -7.0/2 “Abc” * 2, “Abc” * -2, “Abc” *0, “Abc”* True, 7+True,8.5 +True math.floor(-7.5) ,math.ceil(-8.2), math.ceil(-1), 4**2 ,2**1.2 % operator and modular division of -ve number. Code Exercise: https://repl.it/H5c4/5 https://www.python.org/dev/peps/pep-0238/ ----> Proposal to change division operator
  • 5. Relational Operators == != < > <= >= is is not in Difference between is and == a = ’ abc ’ b = a c = input ( ’ Enter String : ’)
  • 6. Relational Operators An is expression evaluates to True if two variables point to the same (identical) object. An == expression evaluates to True if the objects referred to by the variables are equal (have the same contents). < and > for two strings ord(‘a’) to find ASCII
  • 7. Logical Operators Discuss the truth table: for booleans. And operator: first evaluates its left operand,if false,result is left else right operand Or : evaluates its left operand,if True,the result returned is the value of the left operand; otherwise, right operand. Not operator can only be used as unary operator. True is not True
  • 8. Bit–wise Operators Bitwise operator works on bits and performs bit by bit operation. a = 0011 1100 b = 0000 1101 ----------------- a&b = 0000 1100 a|b = 0011 1101 a^b = 0011 0001 ~a = 1100 0011
  • 9. Bit–wise Operators Left Shift << and right Shift >> Operator Precedence : PEMDAS : Parentheses,Exponentiation,Multiplication.Division,Addition,Substraction * And / has same precedence. + and - has same precedence. Operator with same precedence are evaluated from left to right.
  • 10. Control Flows IF :Used to check a condition: if the condition is true, run a block of statements (called the if-block), else process another block of statements (called the else- block). The else clause is optional. elif: if expression1: statement(s) elif expression2: statement(s) elif expression3: statement(s) else: statement(s)
  • 11. Coding Exercises 1. Input the number from keyboard and check if number is positive or negative. Modify the code and print “Number is Zero” if number is 0. 2. Decide a number and take guesses from the user and check if it is the number that we have. 3. Python Program to check if number is even or odd.
  • 12. // And % 7 3 2 1 -7 3 -3 2 7 -3 -3 -2 -7 -3 2 -1