Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring a number in Python. Possible to emphasize thousand?

Is it possible to declare a number in Python as

a = 35_000
a = 35,000  

Neither seem to work of course. How do you emphasize things like these, for clarity in Python? Is it possible?

like image 952
James Raitsev Avatar asked May 06 '17 06:05

James Raitsev


People also ask

How big of a number can Python handle?

The pythonic way Similarly for python, "digit" is in base 2³⁰ which means it will range from 0 to 2³⁰ - 1 = 1073741823 of the decimal system.

HOW HIGH CAN numbers go in Python?

maxsize is 2**31-1 on a 32-bit environment and 2**63-1 on a 64-bit environment, like sys. maxint in Python2. Converted to binary and hexadecimal numbers with bin() and hex() , sys.

How do you declare a long number in Python?

Type int(x) to convert x to a plain integer. Type long(x) to convert x to a long integer.

What is the largest possible number in Python?

In the approach above we assume that 999999 is the maximum possible value in our list and compare it with other elements to update when a value lesser than it is found.


2 Answers

This is actually just now possible in Python 3.6.

You can use the first format that 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. It's the same as saying:

a = (35, 000)  # Which is also the same as (35, 0).
like image 135
Arya McCarthy Avatar answered Sep 17 '22 17:09

Arya McCarthy


Yes, this is possible starting with python 3.6.

PEP 515 adds the ability to use underscores in numeric literals for improved readability. For example:

>>> 1_000_000_000_000_000
1000000000000000
>>> 0x_FF_FF_FF_FF
4294967295
like image 23
Anonymous Avatar answered Sep 19 '22 17:09

Anonymous