Numeric types in Python:

There are three numeric types in Python:

int: int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
float: Float, or “floating point number” is a number, positive or negative, containing one or more decimals
complex : Complex numbers are written with a “j” as the imaginary part: (e.g. 3+5j).

Example:Numeric types in Python:

Python Numbers:

The interpreter acts as a simple calculator: you can type an expression at it and it will write the value.Expression syntax is straightforward: the operators +, -, * and / work just like in most other languages (for example, Pascal or C); parentheses () can be used for grouping. For example

Fig:Working with numbers in python

Note: Division (/) always returns a float.
To do floor division and get an integer result (discarding any fractional result) you can use the // operator; to calculate the remainder you can use %:

Fig: Classical Division,Floor Division ,% Operator

With Python, it is possible to use the ** operator to calculate powers

Fig:Calculate powers in python

There is full support for floating point; operators with mixed type operands convert the integer operand to floating point:

operators with mixed type operands

variable _ in python:

This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example:

Fig: Example of _ variable

This variable should be treated as read-only by the user. Don’t explicitly assign a value to it — you would create an independent local variable with the same name masking the built-in variable with its magic behavior.

Leave a Comment