python tip

Dividing large numbers in chunks

Let's talk with practicality. Take a look at the numbers below and tell me, which number would you be able to understand and say faster? • 7683423898 • 1,989,738,100 Obviously, you guys are gonna answer that the second one is easier to understand. Why is that? That's because it is divided into thirds. Everybody understands basic maths and knows that the fourth part is the billions. Therefore the number is one billion, nine hundred eighty-nine million, seven hundred thirty-eight thousand, one hundred. This division makes it much faster to understand which part is the billions and which is the millions etc. In Python, you can place underscores in numbers so you can use them to divide up any large number. This will help improve the readability of the data entered as well as the code. Example:

a = 122_343_090
print(a*2 + 32_400)

# or

b = (4_2_8_9) # Only a psychopath is gonna do this🙄