Conversation

K. Ryabitsev šŸ

I was $today years old when I learned that you can write long integers with underscores for readability in Python.

foo = 1_500_000
12
26
56

@monsieuricon also in C (starting with C23) and C++ (since C++14) with apostrophes:

int a = 1'048'576, b = 0xAAAA'AAAA;

0
0
0

@monsieuricon Same thing in Ruby...and presumably other languages

0
0
0

@monsieuricon I feel that changing conventional numbers into unconventional representations of numbers is fundamentally a bad idea. Maybe it's harmless? It feels like it's not.

0
0
0
@vkc I know, right?
0
0
1

@monsieuricon That's was something I knew at one time, but had totally forgotten about.

0
0
0

@monsieuricon It's interesting that this works, but not German, etc., style formating:

>>> 1.200,30
(1.2, 30)

>>> 1_200.30
1200.3

0
0
0

@monsieuricon Notably first introduced in Ada, and then subsequently popularised in Perl. I think quite a few languages support it these days, as it is truly a great readability improvement for large numbers.

0
0
0

@monsieuricon nice feature. Might be interesting to see this in Tcl too, though it would likely break things.

0
0
0

@monsieuricon yup! this works in PHP too. Iā€™m a PHP Dev learning Python. It was a nice surprise when I learned that it works it both languages

0
0
0