DEV Community

Kelvin Wangonya
Kelvin Wangonya

Posted on β€’ Originally published at wangonya.com on

10

1_000_000_000 = 1000000000

With Python 3.6+, you can make long numbers in your code more legible by separating the digits with underscores.

Python 3.7.4 

>>> x = 1_000_000_000 
>>> x
1000000000
Enter fullscreen mode Exit fullscreen mode

Top comments (11)

Collapse
 
ben profile image
Ben Halpern β€’

Same in Ruby πŸ™‚

Collapse
 
luisacosta profile image
Luis Acosta β€’

Same in Java from jdk7 ;)

Collapse
 
wangonya profile image
Kelvin Wangonya β€’ β€’ Edited

Yeah, this is kind of a norm in most programming languages. I'm surprised it wasn't available in Python for so long.

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn β€’

Really? I've seen far more without it than with it. I mean, yeah Ruby can do it, and so can Elixir and Erlang (which while not the originator, is probably the source of influence for many modern languages that can), but other than those three, almost every language I've ever worked with either doesn't support it, or doesn't at all document that it supports it.

In fact, almost three years after it was added to Python, the only places I can find it in their documentation are the formal syntax definition (which next to nobody reads unless they're writing their own Python implementation or parsing tools) and the release notes for 3.6 (which were likely read by only marginally more people than the formal syntax definitions).

Thread Thread
 
wangonya profile image
Kelvin Wangonya β€’

Well, Wikipedia lists Ada, C# (from version 7.0), D, Eiffel, Haskell (from GHC version 8.6.1), Java (from version 7), Julia, Perl, Ruby, and Swift in addition to Python as languages which support that... I guess I read that and interpreted it wrongly as 'most'. I've made the edit. Thanks for the heads-up.

Collapse
 
zeyadetman profile image
Zeyad Etman β€’

same in javascript :D

Collapse
 
dantehemerson profile image
Dante CalderΓ³n β€’

how?

Collapse
 
zeyadetman profile image
Zeyad Etman β€’

Here's a blog post about this: v8.dev/features/numeric-separators

Collapse
 
davidmm1707 profile image
David MMπŸ‘¨πŸ»β€πŸ’» β€’

This is one thing that I know I can do, but I always forget to do.

Collapse
 
nebojsac profile image
Nick Cinger β€’

This was recently added to PHP as well, nice to see good ideas spreading across languages!

Collapse
 
sachadee profile image
SachaDee β€’

Nice one! Thanks!

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay