Python Tip: Improve Readability Using Underscores in Numbers

Python Tip: Improve Readability Using Underscores in Numbers

šŸ Python Tip:

When working with large numbers, Python lets you use underscores (_) to enhance readability.

Here is an example: šŸ‘‡

āŒ # Difficult to read:
gigabit = 1000000000        
ten_gigabit = 10000000000   

āœ… # Easier to read with underscores (_):
gigabit = 1_000_000_000        
ten_gigabit = 10_000_000_000 

print(f"{gigabit=}\n{ten_gigabit=}")
# Output:
# gigabit=1000000000
# ten_gigabit=10000000000

Subscribe to our newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox.
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!