0

I find a weird thing in Python, if I assign a variable as int_int, float_int, int_float, the type will be int, float, float, seems the underline is a join character, like:

x = 100_200

then x will be a int, value is 100200. Can someone explain why and how to reasonable use?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Henry Tsao
  • 13
  • 1

1 Answers1

4

Python 3.6 introduced Underscores in Numeric Literals.

Essentially, this is a readability feature.

Compare:

x = 100000000

and:

x = 100_000_000
Nick is tired
  • 6,860
  • 20
  • 39
  • 51
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257