{
  "id": 8927356,
  "title": "Representing large numbers in python: the underscore separator",
  "url": "https://urgent.news/2026/09/21/representing-large-numbers-in-python-the-underscore-separator",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-21T13:19:01.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/chidambaram_manivannan/representing-large-numbers-in-python-the-underscore-separator-meg"
  },
  "original_language": "en",
  "account": "In Python, representing large numbers can be made easier through the use of an underscore separator. This feature was introduced in Python version 3.6. For instance, the large number 8736570164 could be represented as 8_736_570_164, which is more readable than manually counting the digits or using commas as separators.\n\nUsing underscores in numeric literals does have some rules, however. The number cannot begin or end with an underscore, and multiple underscore separators cannot be placed next to each other. For example, the following would result in an error:\n\n- num = _314 # Error!\n- num = 314 _ # Error!\n- 12 __345 # Error!\n\nUnderscore separators can also be used with floats, but there cannot be an underscore directly next to the decimal point. This would also result in an error:\n\n- num = 3 _ . 141592 # Error\n- num = 3. _141592 # Error\n\nHowever, the correct representation would be:\n\n- num = 3.141_592 # Correct!\n\nIf you need to output an underscore separated number from a normal one, you can convert it to a formatted string. Python adds in the separators based on the International Number System (thousands, millions, billions, etc.). For example:\n\n- num = 1234567890\n- print(f\"{num:_}\") # Output: 1_234_567_890\n\nThis technique can make code easier to read, as numbers are more familiar to humans when they are written with underscores. It's a useful tool for any Python programmer, and can save time and reduce errors when working with large numbers.",
  "summary": "Recently, I learnt a simple way of representing large numbers in python. Say, I had a large number like 8736570164 I had to manually (and erratically) point my finger at the monitor on that number - look for tens, thousands, millions, etc., draw imaginary commas and come to a conclusion, as taught in school. If we cleverly had to include the commas in the number itself, python treats them as…",
  "key_points": [
    "Large numbers in Python can be represented using underscore separator introduced in version 3.6",
    "Underscore cannot start/end number nor be consecutive; causes error",
    "Underscores work with floats but not adjacent to decimal point"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}