Python Operators
With every programming language we have our operators, and Python is no different. Operators in a programming language are used to vaguely describe 5 different areas: arithmetic, assignment, increment/decrement, comparison, logical. There isn't really much need to explain all of them as I have previously in the other categories, which means we will only cover a few of them.
Arithmetic Operators
Example
print (3 + 4) print (3 - 4) print (3 * 4) print (3 / 4) print (3 % 2) print (3 ** 4) # 3 to the fourth power print (3 // 4) #floor division
Result: 7 -1 12 0.75 1 81 0
See, they are pretty standard. I included how to do exponents because it's a little funky, but other than that, they are fairly normal and work as expected. Don't forget that you can use the + sign to concatenate strings. The addition, subtraction, multiplication, and division work just like expected.
You might have not seen the modulus operator before (%). All the modulus operator does is to divide the left side by the right side and get the remainder. So, that remainder is what is returned and not the number of times the right number went into the left number. The double * is just an easy way to provide exponents to Python. Finally, the floor division operator (//) just divides the number and rounds down.
Assignment Operators
These are pretty identical to the previous languages also, but a refresher never hurt anyone. Example please!
Example
a = 0 a+=2 print (a)
Result: 2
Of course, you can do this with any of the previous arithmetic operators as an assignment operator followed by the =. We just told Python to add 2 to the value of a without having to say something like a = a + 2. We are programmers, and we are proud to be called lazy!