An integer is a whole number, commonly used in most programming languages. Integers, (often referred to as an 'int') has no decimal point at the end of it, even if a zero follows the decimal point.
Here is a list of numbers. ALL of these are integers:
- 3
- 67
- 492
- 7969276459827034
- 100000
- 1
Variables can be used to store integer values. If you need to know what a variable is take a look at the chapter entitles 'variables.md'.
Here is an example of a variable with a value that is an integer:
oranges = 6
apples = 9
basket = oranges + apples
print(basket)
Output: 15
When assigning an integer to a variable there is no need for quotation marks or any other defining decoration around the number. Place a number within quotation marks would make the number a 'string' and mathematical equations could not longer be used on the numbers. See the 'string' chapter to find out what a string in Python is.
Dividing two numbers that do not equally part in Python 3 will automatically result in the ouput being a floating number. There is a whole chapter on floating numbers if this concept is new to you. You can tell Python to output integers only by prefixing the argument with 'int'. Here's an example:
print (10 / 3)
>>> 3.333333333
However, you may just want the number 3 on its own rather than this long output. To do this prefix your sum with int, like this:
print (int(10 / 3))
>>> 3
Remember, in Python 3 everything you want to print must be in parethesis, and so must the sum you want to convert to an integer.