SlideShare a Scribd company logo
Title - Sub
Basic Operators
• Python language supports the following types of operators.
 Arithmetic Operators
 Comparison (Relational) Operators
 Assignment Operators
 Logical Operators
 Bitwise Operators
 Membership Operators
 Identity Operators
Python – Arithmetic Operator
a=10, b=20
Addition: a + b = 30
Subtraction: a - b = 20
Multiplication: a * b = 200
Division: a / b = 2
Modulus: a % b = 0
Increment: b++ = 21
Decrement: b-- = 19
Python – Comparison Operator
a=10, b=20
Equal to: a == b : true
Not equal to: a != b : false
Greater than: a > b : false
Less than: a < b : true
Greater than or equal to: a >= b : false
Less than or equal to: a <= b : true
Python – Assignment Operator
Simple assignment operator: c=a+b //assign a+b to c
Add AND assignment operator: c+=a //assign c=c+a
Subtract AND assignment operator: c-=a //assign c=c-a
Multiply AND assignment operator: c*=a //assign c=c*a
Divide AND assignment operator: c/=a //assign c=c/a
Modulus AND assignment operator: c*=a //assign c=c*a
Lest shift AND assignment operator: c<<=2 //assign c=c<<2
Right shift AND assignment operator: c>>=2 //assign c=c>>2
Bitwise AND assignment operator: c&=2 //assign c=c&2
Bitwise exclusive AND assignment operator: c^=2 //assign c=c^2
Bitwise inclusive AND assignment operator: c|=2 //assign c=c|2
Python – Bitwise Operator
//integer format
a=60, b=13
//binary format
a=0011 1100
b=0000 1101
a&b = 0000 1100
a|b = 0011 1101
a^b = 0011 0001
~a = 1100 0011
Python – Logical Operator
a=true
b=false
Logical AND: a AND b : true
Logical OR: a OR b : true
Logical NOT: NOT(a AND b) : false
Python – Membership Operator
• in and not in are the membership operators;
• It is used to test whether a value or variable is in a sequence.
in True if value is found in the sequence
not in True if value is not found in the sequence
# Examples of Membership operator
x = 'Geeks for Geeks'
y = {3:'a',4:'b'}
print('G' in x)
print('geeks' not in x)
print('Geeks' not in x)
print(3 in y)
print('b' in y)
True
True
False
True
False

More Related Content

PPT
7 can ban assembly
PPTX
Linear programming: A Geometric Approach
PPTX
Fuzzy graph
PPTX
2015 phuong phap tinh chuong 2
PDF
Number Theory for Security
PDF
Bài Giảng Và Ngân Hàng Đề Thi OTOMAT
PPT
PDF
Cac phep-biến-hinh-trong-mặt-phẳng-pdf
7 can ban assembly
Linear programming: A Geometric Approach
Fuzzy graph
2015 phuong phap tinh chuong 2
Number Theory for Security
Bài Giảng Và Ngân Hàng Đề Thi OTOMAT
Cac phep-biến-hinh-trong-mặt-phẳng-pdf

Similar to Python Basic Operators (20)

PPTX
Operators in Python
PDF
Python : basic operators
PPTX
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
PPTX
Python programming language introduction unit
PPTX
PYTHON OPERATORS 123Python Operators.pptx
PPTX
Understanding All Types of Operators in Python with Examples"
PPTX
Operators in Python Arithmetic Operators
PPTX
Operators Concept in Python-N.Kavitha.pptx
PPTX
Different Types of Operators in Python.pptx
PPTX
Python Lec-6 Operatorguijjjjuugggggs.pptx
PPTX
Python operators
PPTX
Python notes for students to develop and learn
PPTX
python statement, expressions and operators.pptx
PPTX
python operators.pptx
PPTX
OPERATOR IN PYTHON-PART2
PPTX
Python Operators
PDF
Python basic operators
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 5
PPSX
Python Data Types, Operators and Control Flow
PPTX
Python_Operations - types of the operators
Operators in Python
Python : basic operators
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
Python programming language introduction unit
PYTHON OPERATORS 123Python Operators.pptx
Understanding All Types of Operators in Python with Examples"
Operators in Python Arithmetic Operators
Operators Concept in Python-N.Kavitha.pptx
Different Types of Operators in Python.pptx
Python Lec-6 Operatorguijjjjuugggggs.pptx
Python operators
Python notes for students to develop and learn
python statement, expressions and operators.pptx
python operators.pptx
OPERATOR IN PYTHON-PART2
Python Operators
Python basic operators
Python Programming | JNTUK | UNIT 1 | Lecture 5
Python Data Types, Operators and Control Flow
Python_Operations - types of the operators
Ad

More from Soba Arjun (20)

PDF
Java interview questions
PDF
Java modifiers
PDF
Java variable types
PDF
Java basic datatypes
PDF
Dbms interview questions
PDF
C interview questions
PDF
Technical interview questions
PDF
Php interview questions with answer
PDF
Computer Memory Types - Primary Memory - Secondary Memory
PDF
Birds sanctuaries
PDF
Important operating systems
PDF
Important branches of science
PDF
Important file extensions
PDF
Java Abstraction
PDF
Java Polymorphism
PDF
Java Overriding
PDF
Java Inner Classes
PDF
java Exception
PDF
Java Methods
PDF
java Inheritance
Java interview questions
Java modifiers
Java variable types
Java basic datatypes
Dbms interview questions
C interview questions
Technical interview questions
Php interview questions with answer
Computer Memory Types - Primary Memory - Secondary Memory
Birds sanctuaries
Important operating systems
Important branches of science
Important file extensions
Java Abstraction
Java Polymorphism
Java Overriding
Java Inner Classes
java Exception
Java Methods
java Inheritance
Ad

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Lesson notes of climatology university.
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Sports Quiz easy sports quiz sports quiz
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Insiders guide to clinical Medicine.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Classroom Observation Tools for Teachers
VCE English Exam - Section C Student Revision Booklet
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Lesson notes of climatology university.
Supply Chain Operations Speaking Notes -ICLT Program
Sports Quiz easy sports quiz sports quiz
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Basic Mud Logging Guide for educational purpose
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Insiders guide to clinical Medicine.pdf
Pre independence Education in Inndia.pdf
Microbial disease of the cardiovascular and lymphatic systems
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Complications of Minimal Access Surgery at WLH
Pharma ospi slides which help in ospi learning
Renaissance Architecture: A Journey from Faith to Humanism
STATICS OF THE RIGID BODIES Hibbelers.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Classroom Observation Tools for Teachers

Python Basic Operators

  • 2. Basic Operators • Python language supports the following types of operators.  Arithmetic Operators  Comparison (Relational) Operators  Assignment Operators  Logical Operators  Bitwise Operators  Membership Operators  Identity Operators
  • 3. Python – Arithmetic Operator a=10, b=20 Addition: a + b = 30 Subtraction: a - b = 20 Multiplication: a * b = 200 Division: a / b = 2 Modulus: a % b = 0 Increment: b++ = 21 Decrement: b-- = 19
  • 4. Python – Comparison Operator a=10, b=20 Equal to: a == b : true Not equal to: a != b : false Greater than: a > b : false Less than: a < b : true Greater than or equal to: a >= b : false Less than or equal to: a <= b : true
  • 5. Python – Assignment Operator Simple assignment operator: c=a+b //assign a+b to c Add AND assignment operator: c+=a //assign c=c+a Subtract AND assignment operator: c-=a //assign c=c-a Multiply AND assignment operator: c*=a //assign c=c*a Divide AND assignment operator: c/=a //assign c=c/a Modulus AND assignment operator: c*=a //assign c=c*a Lest shift AND assignment operator: c<<=2 //assign c=c<<2 Right shift AND assignment operator: c>>=2 //assign c=c>>2 Bitwise AND assignment operator: c&=2 //assign c=c&2 Bitwise exclusive AND assignment operator: c^=2 //assign c=c^2 Bitwise inclusive AND assignment operator: c|=2 //assign c=c|2
  • 6. Python – Bitwise Operator //integer format a=60, b=13 //binary format a=0011 1100 b=0000 1101 a&b = 0000 1100 a|b = 0011 1101 a^b = 0011 0001 ~a = 1100 0011
  • 7. Python – Logical Operator a=true b=false Logical AND: a AND b : true Logical OR: a OR b : true Logical NOT: NOT(a AND b) : false
  • 8. Python – Membership Operator • in and not in are the membership operators; • It is used to test whether a value or variable is in a sequence. in True if value is found in the sequence not in True if value is not found in the sequence # Examples of Membership operator x = 'Geeks for Geeks' y = {3:'a',4:'b'} print('G' in x) print('geeks' not in x) print('Geeks' not in x) print(3 in y) print('b' in y) True True False True False