User Tools

Site Tools


add_commas

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
add_commas [2021/01/13 20:48] – [input is a single number; without pandas] rajuadd_commas [2021/01/13 20:57] (current) – [input is a single number; without pandas] raju
Line 3: Line 3:
 search tags | f strings, thousands separator, format integers with commas search tags | f strings, thousands separator, format integers with commas
 ==== input is a single number; without pandas ==== ==== input is a single number; without pandas ====
 +| '{:,}'.format(value) | For Python ≥2.7 |
 +| f'{value:,}' | For Python ≥3.6 |
 +
 <code> <code>
 In [1]: In [1]:
Line 20: Line 23:
 Out[3]: Out[3]:
 '12,345' '12,345'
 +</code>
 +
 +Examples using a print statement
 +<code>
 +In [1]:
 +a = 123456
 +
 +In [2]:
 +print('The magic number is = {alpha:,}'.format(alpha=a))
 +The magic number is = 123,456
 +
 +In [3]:
 +print('The magic number is = {:,}'.format(a))
 +The magic number is = 123,456
 +
 +In [4]:
 +print('The magic number is = {:}'.format(a))
 +The magic number is = 123456
 </code> </code>
  
add_commas.1610570895.txt.gz · Last modified: 2021/01/13 20:48 by raju