1

I can see multiple pages explaining how to format and print numbers in python, but is there a way to write code with large numbers in a readable way?

speed_of_light = 299 792 458       # metres
dist_to_andromeda = 2,537,497      # light years
dia_of_earth_at_eq = 12_756_320    # metres

EDIT: I found the last one working on py36, but what's the solution for those using py35? Isn't there a way other than comments which would be redundant?

Saravanabalagi Ramachandran
  • 8,551
  • 11
  • 53
  • 102

1 Answers1

2

From Python 3.6 there is

dia_of_earth_at_eq = 12_756_320

Is valid code.

See PEP 515: Underscores in Numeric Literals in What's new in Python 3.6

vishes_shell
  • 22,409
  • 6
  • 71
  • 81