






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive overview of python operators, including arithmetic, assignment, comparison, logical, identity, and membership test operators. Each operator is explained with examples, demonstrating its function and usage. The document also references the 'operator' module, enhancing understanding of operator implementation in python. It serves as a useful guide for understanding basic python programming concepts, suitable for beginners and intermediate learners. It includes code snippets and explanations.
Typology: Lecture notes
1 / 12
This page cannot be seen from the preview
Don't miss anything!







Python Operators:
Multiplicatio n
x * y 30 import operator operator.mul( 5 , 6 ) 30
Exponentiation: Left operand raised to the power of right ** operator.pow(a,b) >>> x = 2 ; y = 3
x ** y 8 import operator operator.pow( 2 , 3 ) 8 Division / operator.truediv(a, b) x = 6 ; y = 3 x / y 2 import operator operator.truediv( 6 , 3 ) 2 Floor division: equivila nt to math.floor(a/b) // operator.floordiv(a, b) x = 6 ; y = 5 x // y 1 import operator operator.floordiv( 6 , 5 ) 1
Operator Function Example /= operator.itruediv (a,b)
x = 6 x /= 3 2 import operator x = operator.itruediv( 6 , 3 ) //= operator.ifloordiv (a,b) x = 6 x //= 5 1 import operator operator.ifloordiv( 6 , 5 )
%= operator.imod(a, b)
x = 11 x %= 3 2 import operator operator.imod( 11 , 3 ) 2
Operator Function Description Example
operator.gt(a, b) True if the left operand is higher than the right one
x = 5 ; y = 6 x > y False import operator operator.gt( 5 , 6 ) False < operator.lt(a, b) True if the left operand is lower than right one x = 5 ; y = 6 x < y True import operator operator.lt( 5 , 6 ) True == operator.eq(a ,b) True if the operands are equal x = 5 ; y = 6 x == y False import operator operator.eq( 5 , 6 ) False