Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Integer

integers are any non-decimal number essentially. Examples include

3 # is the number 3

We can do math on integers

# Math is what you would expect
print(1 + 1)   # => 2
print(8 - 1)   # => 7
print(10 * 2)  # => 20
print(35 / 5)  # => 7.0

note that last answer, 7.0, not as 7, thats our next datatype, Float or floating point number. If you want to do specifically integer division, that is done with //

# Floor division rounds towards negative infinity
print(5 // 3)       # => 1
print(-5 // 3)      # => -2
print(5.0 // 3.0)   # => 1.0  # works on floats too
print(-5.0 // 3.0)  # => -2.0

Contributors: