Python Lessons – 1.2 Simple operations

Python Lessons - 1.2 Simple operations
Scrivi una didascalia…

Arithmetic calculations

Python allows you to perform arithmetic calculations in real time as if it were a calculator. You can directly enter values for operations on a single line.

The spaces inserted between the operators and the operands are not mandatory but if you want to follow the programming standards for Python it is good to always do it (see article on PEP8 – Programming Python with style).

[Python 2.7]: In this version the division returns non-float integers.

The sign – in front of the numbers indicates the negative numbers

The + sign in front of positive numbers is formally correct but does not lead to any effect.

Divisions by zero

Dividing a number by zero produces an error.

The Python console gives us a message with the type of error, in this case ZeroDivisionError, with an explanatory message “integer division or modulo by zero”


References

⇐ Go to Python Lesson 1.1 – The Python console

Go to Python Lesson 1.3 – Floating numbers ⇒

Leave a Reply