Python Main Operators
Contents
Python Main Operators#
Basic operators … You will never need a calculator again!#
In Python, there are different types of operators (special symbols) that operate on different values. Some of the basic operators include:
arithmetic operators
+(addition)-(subtraction)*(multiplication)/(division)//(integer division)%(modulus … this means the remainder if doing junior school division. So if 9 / 4 is equal to “2 remainder 1” then 9 % 4 is equal to 1 and 9 // 4 is equal to 2)**(exponent)
assignment operators
=(assign a value)
comparison operators (return either
TrueorFalse)==(equal to)!=(not equal to)<(less than)<=(less than or equal to)>(greater than)>=(greater than or equal to)
When multiple operators are used in a single expression, operator precedence determines which parts of the expression are evaluated in which order. Operators with higher precedence are evaluated first (like PEMDAS/BODMAS in math). Operators with the same precedence are evaluated from left to right.
()parentheses, for grouping**exponent*,/multiplication and division+,-addition and subtraction==,!=,<,<=,>,>=comparisons