This question already has answers here:
With Python 3.6 (and
PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.
Examples of use:
a = 1_00_00 # you do not need to group digits by 3!
b = 0xbad_c0ffee # you can make fun with hex digit notation
c = 0b0101_01010101010_0100 # works with binary notation
f = 1_000_00.0
A = 1__000 # SyntaxError: invalid token
Underscores in Numeric Literals, grouping decimal numbers by thousands amount = 10_000_000.0 The underscores have no semantic meaning, and literals are parsed as if underscore. (ʌndəʳskɔːʳ ) Word forms: 3rd person singular present tense underscores , present participle underscoring , past tense, past participle underscored. 1. verb. If something such as an action or an event underscores another, it draws attention to the other thing and emphasizes its importance . [mainly US]
Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:
x = 1_000_000
is interpreted to be the same as this:
x = 1000000
However, you can't put two underscores right next to each other like this:
x = 1__000__000 #SyntaxError
PEP 515 -- Underscores in Numeric Literals, For instance, if our code contains numbers with many digits, we can use an underscore character to separate digits in groups of three, similar to how we would / ˈʌn.dɚ.skɔːr / the character _ on a computer keyboard, used to draw a line under a letter or word, and also used in file names where a space is not allowed Thesaurus: synonyms and related words (Definition of underscore from the Cambridge Advanced Learner's Dictionary & Thesaurus © Cambridge University Press)
In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.
Underscore, Underscore definition is - to draw a line under : underline. How to use underscore Verb These failures underscore the difficulty of what we're attempting to do. Underscore definition, to mark with a line or lines underneath; underline, as for emphasis. See more.
Using underscore in Numeric Literals in Java, Literally, underscore means “to underline,” or draw a line beneath a word to on the job, for instance, the event would underscore the need for workplace safety. Favorite Answer It's a notation specific to writing math on the internet, and means that the character that follows is a subscript. For instance, Z_2 = Z₂. The Meaning of Underscores in Python – dbader.org, By the way, there are rules to use underscore in numeric literals, How underscore in numbers are implemented in Java why have you asked to never use the above on the production code ?? what does that mean?? They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this: x = 1_000_000 is interpreted to be the same as this: x = 1000000 However, you can't put two underscores right next to each other like this: x = 1__000__000 #SyntaxError
Underscore, Computer dictionary definition for what underscore means including related If you are trying to underline any letter, number, or other text, the Re:Why do people still use an underscore in file names - isn't that antiquated? 2013/09/05 06:42:39 I must be the exception, because I use both spaces and underscores, depending on circumstances. The practical/obsessive-compulsive side of me saves all my documents using spaces.
Comments can't help but rant a bit about this new "feature"... i had a script that attempted to convert a string into number while on failing simply returned the string itself. this is used for interpreting a mixed-type input data file. '_' was used as a delimiter to combine two integer id's in some fields and all of a sudden (after python 3.6 upgrade), these fields are converted into one integer! IMHO, this sort of warning-less change (silently break perfectly working non-hacky code) should only be allowed in the absolutely necessary scenarios. nicely formatting a large int hardly justifies it. In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore