Python as a calculator
Now, we're going to show you a completely new side of the print() function. You already know that the function. You already know that they function is able to show you the values of the literals passed to it by arguments.
In fact, it can do something more. Take a look at the snippert:
print(2+2)
retype the code in the editor and run it. Can you guess the output?
4
You should see the number four. Feel free to experiment with other operators.
Without taking this too seriously, you've just discovered that Python can be used as a calculator. Not a very handy one, and definitely not a pocket one, but a calculator nonetheless.
Taking it more seriously, we are now entering the province of operators and expressions.
Basic operators
An operator is a symbol of the programming language, which is able to operate on the values.
For example, just as in arithmetic, the + (plus) sign is the operator which is able to add two numbers, giving the result of the addition.
Not all Python operators are as obvious as the plus sign, through, so let's go through some of the operators available in Python, and we'll explain which rules govern their use, and how to interpret the operations they perform.
We'll begin with the operators which are associated with the most widely recognizable arithmetic operations:
+, -, *, /, //, %, **
The order of their appearance is not accidental. We'll talk more about it once we've gone through them all.
Remember: Data and operators when connected together form expressions. The simplest expression is the literal itself.