Numbers represent quantity. In Python, everything is an object including numbers. Python supports integers, floating-point numbers and complex numbers.

An integer is a whole number with no decimal places. The name for the integer data type is int. Python 2 has two integer types — int and long. There is no ‘long integer’ in Python 3 anymore.

A floating-point number, or float for short, is a number with a decimal place. They represent real numbers and are written with a decimal point dividing the integer and the fractional parts. The name of the floating-point data type is float.

We use equal sign to assign labels to variables.

  • Names cannot start with a number.
  • There can be no spaces in the name, use _ instead.
  • Can’t use any of these symbols :’”,<>/?|\()!@#$%^&*~-+
  • It’s considered best practice (PEP8) that names are lowercase.
  • Avoid using the characters ‘l’ (lowercase letter el), ‘O’ (uppercase letter oh), or ‘I’ (uppercase letter eye) as single character variable names.
  • Avoid using words that have special meaning in Python like “list” and “str”.

The numbers we deal with every day are of the decimal (base 10) number system. The embedded programmers need to work with binary (base 2), hexadecimal (base 16) and octal (base 8) number systems. In Python, these numbers are represented by placing a prefix before that number.

The Python has built-in library to operate with numbers. The numbers module defines an abstract hierarchy of numeric types. The math and cmath modules contain various mathematical functions for floating-point and complex numbers. The decimal module supports exact representations of decimal numbers, using arbitrary precision arithmetic. For further details go to this link.

Practice Examples

Go to this link, where you will find examples on how to operate with numbers.