Declaring a number in Python. Can I single out a thousand?

Is it possible to declare a number in Python as

a = 35_000
a = 35,000  

None of them seem to work. How do you emphasize things like clarity in Python? Is it possible?

+4
source share
2 answers

This is actually in Python 3.6.

You can use the first format you showed:

a = 35_000

because underscores are now an accepted separator in numbers. (You could even say a = 3_5_00_0, though why would you?)

The second method you showed will actually create a tuple. This is the same as saying:

a = (35, 000)  # Which is also the same as (35, 0).
+5
source

Yes, this is possible starting with python 3.6 .

PEP 515 . :

>>> 1_000_000_000_000_000
1000000000000000
>>> 0x_FF_FF_FF_FF
4294967295
+3

Source: https://habr.com/ru/post/1676537/


All Articles