Introduction to Numbers

Numbers provide literal or scalar storage and direct access. Numbers are also an immutable type, meaning that changing or updating its value results in a newly allocated object. This activity is, of course, transparent to both the programmer and the user, so it should not change the way the application is developed.
Python has four types of numbers: “plain” integers, long integers, floating point real
numbers, and complex numbers.

How to Create and Assign Numbers

Creating numbers is as simple as assigning a value to a variable:

>>> anInt = 1
>>> laLong = -999999999
>>> aFloat = 3.1415253589793238426433832795
>>> aComplex = 1.23 + 4.56J

How to Update Numbers

You can “update” an existing number by (re)assigning a variable to another number. The new value can be related to its previous value or to a completely different number altogether.

>>> anInt = anInt +10
>>> anInt

How to Remove Numbers

Under normal circumstances, you do not really “remove” a number; you just stop using it! If you really want to delete a reference to a number object, just use the del statement. Example as :

>>> anInt
>>> del (anInt)
>>> anInt
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
NameError: name 'anInt' is not defined

You may also like...