What does underscore in a number mean? [duplicate]
This question already has an answer here:
How to use digit separators for Python integer literals?
4 answers
What do 1_000 and 100_000 mean? [duplicate]
2 answers
Declaring a number in Python. Possible to emphasize thousand?
2 answers
I am wondering why the following variable is treated like a number?
a = 1_000_000
print (a)
1000000
Shouldn't print(a)
return 1_000_000
?
python python-3.x
marked as duplicate by coldspeed
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 16:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to use digit separators for Python integer literals?
4 answers
What do 1_000 and 100_000 mean? [duplicate]
2 answers
Declaring a number in Python. Possible to emphasize thousand?
2 answers
I am wondering why the following variable is treated like a number?
a = 1_000_000
print (a)
1000000
Shouldn't print(a)
return 1_000_000
?
python python-3.x
marked as duplicate by coldspeed
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 16:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to use digit separators for Python integer literals?
4 answers
What do 1_000 and 100_000 mean? [duplicate]
2 answers
Declaring a number in Python. Possible to emphasize thousand?
2 answers
I am wondering why the following variable is treated like a number?
a = 1_000_000
print (a)
1000000
Shouldn't print(a)
return 1_000_000
?
python python-3.x
This question already has an answer here:
How to use digit separators for Python integer literals?
4 answers
What do 1_000 and 100_000 mean? [duplicate]
2 answers
Declaring a number in Python. Possible to emphasize thousand?
2 answers
I am wondering why the following variable is treated like a number?
a = 1_000_000
print (a)
1000000
Shouldn't print(a)
return 1_000_000
?
This question already has an answer here:
How to use digit separators for Python integer literals?
4 answers
What do 1_000 and 100_000 mean? [duplicate]
2 answers
Declaring a number in Python. Possible to emphasize thousand?
2 answers
python python-3.x
python python-3.x
asked Jan 2 at 16:24
sophrossophros
2,8351932
2,8351932
marked as duplicate by coldspeed
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 16:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by coldspeed
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 2 at 16:43
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
add a comment |
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
add a comment |
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.
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
add a comment |
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
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
add a comment |
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
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
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
print(a,b,c,f)
10000
50159747054
174756
100000.0
print(int('1_000_000'))
print(int('0xbad_c0ffee', 16))
print(int('0b0101_01010101010_0100',2))
print(float('1_000_00.0'))
1000000
50159747054
174756
100000.0
A = 1__000 # SyntaxError: invalid token
edited Jan 2 at 16:31
answered Jan 2 at 16:24
sophrossophros
2,8351932
2,8351932
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Jan 2 at 16:28
Supa Mega Ducky Momo da WaffleSupa Mega Ducky Momo da Waffle
2,00431029
2,00431029
add a comment |
add a comment |
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.
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
add a comment |
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.
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
add a comment |
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.
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.
answered Jan 2 at 16:36
AcccumulationAcccumulation
1,39329
1,39329
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
add a comment |
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
1
1
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore
– Neil G
Jan 9 at 22:37
add a comment |