We touched on how numbers work in Python a while back in the beginning of our series on Python. In the past few tutorials we discussed strings and how to manipulate them and some of the string methods. Here, in this article, we will go over some of the math modules and discuss different uses for numbers in Python.
Intergalactic Integers Intentionally Invaded Iraq Intent on Infiltrating Its Islamic Oil
Yeah you heard me. Try saying that headline three times fast. Or even slow. Although I am sure there is a way we could do just that with our Python integers, it won't be the focus of today's article. Instead we will cover more fascinating subjects, like explaining why our buddy Python has two types of integers. Shocking, I know.
As you know, integers are whole numbers, both positive and negative, that do not have a value to the right of the decimal point. There are two kinds of integers in Python: regular and long.
The reason for the two types of integers is that computers handle data larger than 32 bytes by assigning the suffix L to the end of the integer. Any number less than 2,147,483,647 is considered a regular integer; anything larger is a long integer. To see an example of what I mean, type the following at your command prompt:
>>> num=2147483647
>>> num*1
2147483647
Now to see a long, we are going to add one to our number: