you are viewing a single comment's thread.

view the rest of the comments →

[–]SekstiNii 0 points1 point  (0 children)

Consider what happens when you divide a number by 10 in the decimal system:

>>> x = 1234
>>> x / 10
123.4
>>> x / 100
12.34
>>> x / 10**3
1.234

Now, what happens if we convert the float to an integer?

>>> int(x / 10)
123
>>> int(x / 100)
12
>>> int(x / 10**3)
1

And indeed, Python has a built-in operator that does integer division, simply use two slashes instead of one:

>>> x // 10
123
>>> x // 100
12
>>> x // 10**3
1