# What”s the difference between str.isdigit, isnumeric and isdecimal in python?

isdigit | StackOverflow

When I run these methods

``````s.isdigit()
s.isnumeric()
s.isdecimal()
``````

I always got as output or all `True`, or all `False` for each value of `s` (which is of course a string). What"s‚Äã the difference between the three? Can you provide an example that gives two `True`s and one `False` (or vice versa)?

It"s mostly about unicode classifications. Here"s some examples to show discrepancies:

``````>>> def spam(s):
...     for attr in "isnumeric", "isdecimal", "isdigit":
...         print(attr, getattr(s, attr)())
...
>>> spam("¬Ω")
isnumeric True
isdecimal False
isdigit False
>>> spam("¬≥")
isnumeric True
isdecimal False
isdigit True
``````

Specific behaviour is in the official docs here.

Script to find all of them:

``````import sys
import unicodedata
from collections import defaultdict

d = defaultdict(list)
for i in range(sys.maxunicode + 1):
s = chr(i)
t = s.isnumeric(), s.isdecimal(), s.isdigit()
if len(set(t)) == 2:
try:
name = unicodedata.name(s)
except ValueError:
name = f"codepoint{i}"
print(s, name)
d[t].append(s)
``````

By definition, `isdecimal()` ‚äÜ `isdigit()` ‚äÜ `isnumeric()`. That is, if a string is `decimal`, then it"ll also be `digit` and `numeric`.

Therefore, given a string `s` and test it with those three methods, there"ll only be 4 types of results.

``````+-------------+-----------+-------------+----------------------------------+
| isdecimal() | isdigit() | isnumeric() |          Example                 |
+-------------+-----------+-------------+----------------------------------+
|  False      |    True   |    True     | "‚Å∞¬≥‚Å∏", "üÑÄ‚íä‚íè", "‚ì™‚ë¢‚ëß"          |
|  False      |  False    |    True     | "‚Üâ‚Öõ‚Öò", "‚Ö†‚Ö¢‚Öß", "‚ë©‚ë¨„äø", "Â£πË≤≥ÂèÉ"  |
|  False      |  False    |  False      | "abc", "38.0", "-38"             |
+-------------+-----------+-------------+----------------------------------+
``````

1. Some examples of characters `isdecimal()==True`

(thus `isdigit()==True` and `isnumeric()==True`)

``````"0123456789"  DIGIT ZERO~NINE
"‡πê‡πë‡πí‡πì‡πî‡πï‡πñ‡πó‡πò‡πô"  THAI DIGIT ZERO~NINE
"‡ªê‡ªë‡ªí‡ªì‡ªî‡ªï‡ªñ‡ªó‡ªò‡ªô"  LAO DIGIT ZERO~NINE
"·ÅÄ·ÅÅ·ÅÇ·ÅÉ·ÅÑ·ÅÖ·ÅÜ·Åá·Åà·Åâ"  MYANMAR DIGIT ZERO~NINE
"ÔºêÔºëÔºíÔºìÔºîÔºïÔºñÔºóÔºòÔºô"  FULLWIDTH DIGIT ZERO~NINE
"ùüéùüèùüêùüëùüíùüìùüîùüïùüñùüó"  MATHEMATICAL BOLD DIGIT ZERO~NINE
"ùüòùüôùüöùüõùüúùüùùüûùüüùü†ùü°"  MATHEMATICAL DOUBLE-STRUCK DIGIT ZERO~NINE
"ùü¨ùü≠ùüÆùüØùü∞ùü±ùü≤ùü≥ùü¥ùüµ"  MATHEMATICAL SANS-SERIF BOLD DIGIT ZERO~NINE
"ùü∂ùü∑ùü∏ùüπùü∫ùüªùüºùüΩùüæùüø"  MATHEMATICAL MONOSPACE DIGIT ZERO~NINE
``````

2. Some examples of characters `isdecimal()==False` but `isdigit()==True`

(thus `isnumeric()==True`)

``````"‚Å∞¬π¬≤¬≥‚Å¥‚Åµ‚Å∂‚Å∑‚Å∏‚Åπ"  SUPERSCRIPT ZERO~NINE
"‚ÇÄ‚ÇÅ‚ÇÇ‚ÇÉ‚ÇÑ‚ÇÖ‚ÇÜ‚Çá‚Çà‚Çâ"  SUBSCRIPT ZERO~NINE
"üÑÄ‚íà‚íâ‚íä‚íã‚íå‚íç‚íé‚íè‚íê"  DIGIT ZERO~NINE FULL STOP
"üÑÅüÑÇüÑÉüÑÑüÑÖüÑÜüÑáüÑàüÑâüÑä"  DIGIT ZERO~NINE COMMA
"‚ì™‚ë†‚ë°‚ë¢‚ë£‚ë§‚ë•‚ë¶‚ëß‚ë®"  CIRCLED DIGIT ZERO~NINE
"‚ìø‚ù∂‚ù∑‚ù∏‚ùπ‚ù∫‚ùª‚ùº‚ùΩ‚ùæ"  NEGATIVE CIRCLED DIGIT ZERO~NINE
"‚ë¥‚ëµ‚ë∂‚ë∑‚ë∏‚ëπ‚ë∫‚ëª‚ëº"  PARENTHESIZED DIGIT ONE~NINE
"‚ûÄ‚ûÅ‚ûÇ‚ûÉ‚ûÑ‚ûÖ‚ûÜ‚ûá‚ûà"  DINGBAT CIRCLED SANS-SERIF DIGIT ONE~NINE
"‚ìµ‚ì∂‚ì∑‚ì∏‚ìπ‚ì∫‚ìª‚ìº‚ìΩ"  DOUBLE CIRCLED DIGIT ONE~NINE
"‚ûä‚ûã‚ûå‚ûç‚ûé‚ûè‚ûê‚ûë‚ûí"  DINGBAT NEGATIVE CIRCLED SANS-SERIF DIGIT ONE~NINE
``````

3. Some examples of characters `isdecimal()==False` and `isdigit()==False` but `isnumeric()==True`

``````"¬Ω‚Öì¬º‚Öï‚Öô‚Öê‚Öõ‚Öë‚Öí‚Öî¬æ‚Öñ‚Öó‚Öò‚Öö‚Öú‚Öù‚Öû‚Öü‚Üâ"  VULGAR FRACTION
"‡ß¥‡ßµ‡ß∂‡ß∑‡ß∏‡ßπ"  BENGALI CURRENCY NUMERATOR
"‡Ø∞‡Ø±‡Ø≤"  TAMIL NUMBER TEN, ONE HUNDRED, ONE THOUSAND
"‡±∏‡±π‡±∫‡±ª‡±º‡±Ω‡±æ"  TELUGU FRACTION DIGIT
"‡µ∞‡µ±‡µ≤‡µ≥‡µ¥‡µµ"  MALAYALAM NUMBER, MALAYALAM FRACTION
"‡º≥‡º™‡º´‡º¨‡º≠‡ºÆ‡ºØ‡º∞‡º±‡º≤"  TIBETAN DIGIT HALF ZERO~NINE
"·ç≤·ç≥·ç¥·çµ·ç∂·ç∑·ç∏·çπ·ç∫·çª·çº"  ETHIOPIC NUMBER TEN~NINETY, HUNDRED, TEN THOUSAND
"·ü∞·ü±·ü≤·ü≥·ü¥·üµ·ü∂·ü∑·ü∏·üπ"  KHMER SYMBOL LEK ATTAK
"‚Ö∞‚Ö±‚Ö≤‚Ö≥‚Ö¥‚Öµ‚Ö∂‚Ö∑‚Ö∏‚Öπ‚Ö∫‚Öª‚Öº‚ÖΩ‚Öæ‚Öø"  SMALL ROMAN NUMERAL
"‚ÜÄ‚ÜÅ‚ÜÇ‚ÜÖ‚ÜÜ"  ROMAN NUMERAL
"„âà„ââ„âä„âã„âå„âç„âé„âè"  CIRCLED NUMBER TEN~EIGHTY ON BLACK SQUARE
"‚ëΩ‚ëæ‚ëø‚íÄ‚íÅ‚íÇ‚íÉ‚íÑ‚íÖ‚íÜ‚íá"  PARENTHESIZED NUMBER TEN~TWENTY
"‚íë‚íí‚íì‚íî‚íï‚íñ‚íó‚íò‚íô‚íö‚íõ"  NUMBER TEN~TWENTY FULL STOP
"‚ì´‚ì¨‚ì≠‚ìÆ‚ìØ‚ì∞‚ì±‚ì≤‚ì≥‚ì¥"  NEGATIVE CIRCLED NUMBER ELEVEN
"‚ìæ‚ûâ‚ùø‚ûì"  various styles of CIRCLED NUMBER TEN
"üÑå"  DINGBAT NEGATIVE CIRCLED SANS-SERIF DIGIT ZERO
"„Äá"  IDEOGRAPHIC NUMBER ZERO
"„Ä°„Ä¢„Ä£„Ä§„Ä•„Ä¶„Äß„Ä®„Ä©„Ä∏„Äπ„Ä∫"  HANGZHOU NUMERAL ONE~TEN, TWENTY, THIRTY
"„Üí„Üì„Üî„Üï"  IDEOGRAPHIC ANNOTATION ONE~FOUR MARK
"„äÄ„äÅ„äÇ„äÉ„äÑ„äÖ„äÜ„äá„äà„äâ"  CIRCLED IDEOGRAPH ONE~TEN
"Ô•´Ô•≥Ô•∏Ô¶≤ÔßëÔßìÔßΩ"  CJK COMPATIBILITY IDEOGRAPH
"êÑáêÑàêÑâêÑäêÑãêÑåêÑçêÑéêÑèêÑêêÑëêÑíêÑìêÑîêÑïêÑñêÑóêÑò"  AEGEAN NUMBER ONE~NINE, TEN~NINETY
"êÑôêÑöêÑõêÑúêÑùêÑûêÑüêÑ†êÑ°êÑ¢êÑ£êÑ§êÑ•êÑ¶êÑßêÑ®êÑ©êÑ™"  AEGEAN NUMBER ONE~NINE HUNDRED, ONE~NINE THOUSAND
"êÑ¨êÑ≠êÑÆêÑØêÑ∞êÑ±êÑ≤êÑ≥"  AEGEAN NUMBER TEN~NINETY THOUSAND
"ùç†ùç°ùç¢ùç£ùç§ùç•ùç¶ùçßùç®"  COUNTING ROD UNIT DIGIT ONE~NINE
"ùç©ùç™ùç´ùç¨ùç≠ùçÆùçØùç∞ùç±"  COUNTING ROD TENS DIGIT ONE~NINE
``````

## What"s the difference between str.isdigit, isnumeric and isdecimal in python?

When I run these methods

``````s.isdigit()
s.isnumeric()
s.isdecimal()
``````

I always got as output or all `True`, or all `False` for each value of `s` (which is of course a string). What"s‚Äã the difference between the three? Can you provide an example that gives two `True`s and one `False` (or vice versa)?

It"s mostly about unicode classifications. Here"s some examples to show discrepancies:

``````>>> def spam(s):
...     for attr in "isnumeric", "isdecimal", "isdigit":
...         print(attr, getattr(s, attr)())
...
>>> spam("¬Ω")
isnumeric True
isdecimal False
isdigit False
>>> spam("¬≥")
isnumeric True
isdecimal False
isdigit True
``````

Specific behaviour is in the official docs here.

Script to find all of them:

``````import sys
import unicodedata
from collections import defaultdict

d = defaultdict(list)
for i in range(sys.maxunicode + 1):
s = chr(i)
t = s.isnumeric(), s.isdecimal(), s.isdigit()
if len(set(t)) == 2:
try:
name = unicodedata.name(s)
except ValueError:
name = f"codepoint{i}"
print(s, name)
d[t].append(s)
``````

If you know it will be only one number in the string, i.e `"hello 12 hi"`, you can try `filter`.

For example:

``````In [1]: int("".join(filter(str.isdigit, "200 grams")))
Out[1]: 200
In [2]: int("".join(filter(str.isdigit, "Counters: 55")))
Out[2]: 55
In [3]: int("".join(filter(str.isdigit, "more than 23 times")))
Out[3]: 23
``````

But be carefull !!! :

``````In [4]: int("".join(filter(str.isdigit, "200 grams 5")))
Out[4]: 2005
``````

By definition, `isdecimal()` ‚äÜ `isdigit()` ‚äÜ `isnumeric()`. That is, if a string is `decimal`, then it"ll also be `digit` and `numeric`.

Therefore, given a string `s` and test it with those three methods, there"ll only be 4 types of results.

``````+-------------+-----------+-------------+----------------------------------+
| isdecimal() | isdigit() | isnumeric() |          Example                 |
+-------------+-----------+-------------+----------------------------------+
|  False      |    True   |    True     | "‚Å∞¬≥‚Å∏", "üÑÄ‚íä‚íè", "‚ì™‚ë¢‚ëß"          |
|  False      |  False    |    True     | "‚Üâ‚Öõ‚Öò", "‚Ö†‚Ö¢‚Öß", "‚ë©‚ë¨„äø", "Â£πË≤≥ÂèÉ"  |
|  False      |  False    |  False      | "abc", "38.0", "-38"             |
+-------------+-----------+-------------+----------------------------------+
``````

1. Some examples of characters `isdecimal()==True`

(thus `isdigit()==True` and `isnumeric()==True`)

``````"0123456789"  DIGIT ZERO~NINE
"‡πê‡πë‡πí‡πì‡πî‡πï‡πñ‡πó‡πò‡πô"  THAI DIGIT ZERO~NINE
"‡ªê‡ªë‡ªí‡ªì‡ªî‡ªï‡ªñ‡ªó‡ªò‡ªô"  LAO DIGIT ZERO~NINE
"·ÅÄ·ÅÅ·ÅÇ·ÅÉ·ÅÑ·ÅÖ·ÅÜ·Åá·Åà·Åâ"  MYANMAR DIGIT ZERO~NINE
"ÔºêÔºëÔºíÔºìÔºîÔºïÔºñÔºóÔºòÔºô"  FULLWIDTH DIGIT ZERO~NINE
"ùüéùüèùüêùüëùüíùüìùüîùüïùüñùüó"  MATHEMATICAL BOLD DIGIT ZERO~NINE
"ùüòùüôùüöùüõùüúùüùùüûùüüùü†ùü°"  MATHEMATICAL DOUBLE-STRUCK DIGIT ZERO~NINE
"ùü¨ùü≠ùüÆùüØùü∞ùü±ùü≤ùü≥ùü¥ùüµ"  MATHEMATICAL SANS-SERIF BOLD DIGIT ZERO~NINE
"ùü∂ùü∑ùü∏ùüπùü∫ùüªùüºùüΩùüæùüø"  MATHEMATICAL MONOSPACE DIGIT ZERO~NINE
``````

2. Some examples of characters `isdecimal()==False` but `isdigit()==True`

(thus `isnumeric()==True`)

``````"‚Å∞¬π¬≤¬≥‚Å¥‚Åµ‚Å∂‚Å∑‚Å∏‚Åπ"  SUPERSCRIPT ZERO~NINE
"‚ÇÄ‚ÇÅ‚ÇÇ‚ÇÉ‚ÇÑ‚ÇÖ‚ÇÜ‚Çá‚Çà‚Çâ"  SUBSCRIPT ZERO~NINE
"üÑÄ‚íà‚íâ‚íä‚íã‚íå‚íç‚íé‚íè‚íê"  DIGIT ZERO~NINE FULL STOP
"üÑÅüÑÇüÑÉüÑÑüÑÖüÑÜüÑáüÑàüÑâüÑä"  DIGIT ZERO~NINE COMMA
"‚ì™‚ë†‚ë°‚ë¢‚ë£‚ë§‚ë•‚ë¶‚ëß‚ë®"  CIRCLED DIGIT ZERO~NINE
"‚ìø‚ù∂‚ù∑‚ù∏‚ùπ‚ù∫‚ùª‚ùº‚ùΩ‚ùæ"  NEGATIVE CIRCLED DIGIT ZERO~NINE
"‚ë¥‚ëµ‚ë∂‚ë∑‚ë∏‚ëπ‚ë∫‚ëª‚ëº"  PARENTHESIZED DIGIT ONE~NINE
"‚ûÄ‚ûÅ‚ûÇ‚ûÉ‚ûÑ‚ûÖ‚ûÜ‚ûá‚ûà"  DINGBAT CIRCLED SANS-SERIF DIGIT ONE~NINE
"‚ìµ‚ì∂‚ì∑‚ì∏‚ìπ‚ì∫‚ìª‚ìº‚ìΩ"  DOUBLE CIRCLED DIGIT ONE~NINE
"‚ûä‚ûã‚ûå‚ûç‚ûé‚ûè‚ûê‚ûë‚ûí"  DINGBAT NEGATIVE CIRCLED SANS-SERIF DIGIT ONE~NINE
``````

3. Some examples of characters `isdecimal()==False` and `isdigit()==False` but `isnumeric()==True`

``````"¬Ω‚Öì¬º‚Öï‚Öô‚Öê‚Öõ‚Öë‚Öí‚Öî¬æ‚Öñ‚Öó‚Öò‚Öö‚Öú‚Öù‚Öû‚Öü‚Üâ"  VULGAR FRACTION
"‡ß¥‡ßµ‡ß∂‡ß∑‡ß∏‡ßπ"  BENGALI CURRENCY NUMERATOR
"‡Ø∞‡Ø±‡Ø≤"  TAMIL NUMBER TEN, ONE HUNDRED, ONE THOUSAND
"‡±∏‡±π‡±∫‡±ª‡±º‡±Ω‡±æ"  TELUGU FRACTION DIGIT
"‡µ∞‡µ±‡µ≤‡µ≥‡µ¥‡µµ"  MALAYALAM NUMBER, MALAYALAM FRACTION
"‡º≥‡º™‡º´‡º¨‡º≠‡ºÆ‡ºØ‡º∞‡º±‡º≤"  TIBETAN DIGIT HALF ZERO~NINE
"·ç≤·ç≥·ç¥·çµ·ç∂·ç∑·ç∏·çπ·ç∫·çª·çº"  ETHIOPIC NUMBER TEN~NINETY, HUNDRED, TEN THOUSAND
"·ü∞·ü±·ü≤·ü≥·ü¥·üµ·ü∂·ü∑·ü∏·üπ"  KHMER SYMBOL LEK ATTAK
"‚Ö∞‚Ö±‚Ö≤‚Ö≥‚Ö¥‚Öµ‚Ö∂‚Ö∑‚Ö∏‚Öπ‚Ö∫‚Öª‚Öº‚ÖΩ‚Öæ‚Öø"  SMALL ROMAN NUMERAL
"‚ÜÄ‚ÜÅ‚ÜÇ‚ÜÖ‚ÜÜ"  ROMAN NUMERAL
"„âà„ââ„âä„âã„âå„âç„âé„âè"  CIRCLED NUMBER TEN~EIGHTY ON BLACK SQUARE
"‚ëΩ‚ëæ‚ëø‚íÄ‚íÅ‚íÇ‚íÉ‚íÑ‚íÖ‚íÜ‚íá"  PARENTHESIZED NUMBER TEN~TWENTY
"‚íë‚íí‚íì‚íî‚íï‚íñ‚íó‚íò‚íô‚íö‚íõ"  NUMBER TEN~TWENTY FULL STOP
"‚ì´‚ì¨‚ì≠‚ìÆ‚ìØ‚ì∞‚ì±‚ì≤‚ì≥‚ì¥"  NEGATIVE CIRCLED NUMBER ELEVEN
"‚ìæ‚ûâ‚ùø‚ûì"  various styles of CIRCLED NUMBER TEN
"üÑå"  DINGBAT NEGATIVE CIRCLED SANS-SERIF DIGIT ZERO
"„Äá"  IDEOGRAPHIC NUMBER ZERO
"„Ä°„Ä¢„Ä£„Ä§„Ä•„Ä¶„Äß„Ä®„Ä©„Ä∏„Äπ„Ä∫"  HANGZHOU NUMERAL ONE~TEN, TWENTY, THIRTY
"„Üí„Üì„Üî„Üï"  IDEOGRAPHIC ANNOTATION ONE~FOUR MARK
"„äÄ„äÅ„äÇ„äÉ„äÑ„äÖ„äÜ„äá„äà„äâ"  CIRCLED IDEOGRAPH ONE~TEN
"Ô•´Ô•≥Ô•∏Ô¶≤ÔßëÔßìÔßΩ"  CJK COMPATIBILITY IDEOGRAPH
"êÑáêÑàêÑâêÑäêÑãêÑåêÑçêÑéêÑèêÑêêÑëêÑíêÑìêÑîêÑïêÑñêÑóêÑò"  AEGEAN NUMBER ONE~NINE, TEN~NINETY
"êÑôêÑöêÑõêÑúêÑùêÑûêÑüêÑ†êÑ°êÑ¢êÑ£êÑ§êÑ•êÑ¶êÑßêÑ®êÑ©êÑ™"  AEGEAN NUMBER ONE~NINE HUNDRED, ONE~NINE THOUSAND
"êÑ¨êÑ≠êÑÆêÑØêÑ∞êÑ±êÑ≤êÑ≥"  AEGEAN NUMBER TEN~NINETY THOUSAND
"ùç†ùç°ùç¢ùç£ùç§ùç•ùç¶ùçßùç®"  COUNTING ROD UNIT DIGIT ONE~NINE
"ùç©ùç™ùç´ùç¨ùç≠ùçÆùçØùç∞ùç±"  COUNTING ROD TENS DIGIT ONE~NINE
``````

`str.isdigit()` should do the trick.

Examples:

``````str.isdigit("23") ## True
str.isdigit("abc") ## False
str.isdigit("23.4") ## False
``````

EDIT: As @BuzzMoschetti pointed out, this way will fail for minus number (e.g, "-23"). In case your input_num can be less than 0, use re.sub(regex_search,regex_replace,contents) before applying str.isdigit(). For example:

``````import re
input_num = "-23"
input_num = re.sub("^-", "", input_num) ## "^" indicates to remove the first "-" only
str.isdigit(input_num) ## True
``````

In case you are looking for parsing (positive, unsigned) integers instead of floats, you can use the `isdigit()` function for string objects.

``````>>> a = "03523"
>>> a.isdigit()
True
>>> b = "963spam"
>>> b.isdigit()
False
``````

String Methods - `isdigit()`: Python2, Python3

There"s also something on Unicode strings, which I"m not too familiar with Unicode - Is decimal/decimal

with positive integers you could use `.isdigit`:

``````>>> "16".isdigit()
True
``````

it doesn"t work with negative integers though. suppose you could try the following:

``````>>> s = "-17"
>>> s.startswith("-") and s[1:].isdigit()
True
``````

it won"t work with `"16.0"` format, which is similar to `int` casting in this sense.

edit:

``````def check_int(s):
if s[0] in ("-", "+"):
return s[1:].isdigit()
return s.isdigit()
``````

If you only want to extract only positive integers, try the following:

``````>>> txt = "h3110 23 cat 444.4 rabbit 11 2 dog"
>>> [int(s) for s in txt.split() if s.isdigit()]
[23, 11, 2]
``````

I would argue that this is better than the regex example because you don"t need another module and it"s more readable because you don"t need to parse (and learn) the regex mini-language.

This will not recognize floats, negative integers, or integers in hexadecimal format. If you can"t accept these limitations, jmnas"s answer below will do the trick.

You can use `any` function, with the `str.isdigit` function, like this

``````>>> def has_numbers(inputString):
...     return any(char.isdigit() for char in inputString)
...
>>> has_numbers("I own 1 dog")
True
>>> has_numbers("I own no dog")
False
``````

Alternatively you can use a Regular Expression, like this

``````>>> import re
>>> def has_numbers(inputString):
...     return bool(re.search(r"d", inputString))
...
>>> has_numbers("I own 1 dog")
True
>>> has_numbers("I own no dog")
False
``````

Perhaps you are looking for human sorting (also known as natural sorting):

``````import re

def atoi(text):
return int(text) if text.isdigit() else text

def natural_keys(text):
"""
alist.sort(key=natural_keys) sorts in human order
http://nedbatchelder.com/blog/200712/human_sorting.html
(See Toothy"s implementation in the comments)
"""
return [ atoi(c) for c in re.split(r"(d+)", text) ]

alist=[
"something1",
"something12",
"something17",
"something2",
"something25",
"something29"]

alist.sort(key=natural_keys)
print(alist)
``````

yields

``````["something1", "something2", "something12", "something17", "something25", "something29"]
``````

PS. I"ve changed my answer to use Toothy"s implementation of natural sorting (posted in the comments here) since it is significantly faster than my original answer.

If you wish to sort text with floats, then you"ll need to change the regex from one that matches ints (i.e. `(d+)`) to a regex that matches floats:

``````import re

def atof(text):
try:
retval = float(text)
except ValueError:
retval = text
return retval

def natural_keys(text):
"""
alist.sort(key=natural_keys) sorts in human order
http://nedbatchelder.com/blog/200712/human_sorting.html
(See Toothy"s implementation in the comments)
float regex comes from https://stackoverflow.com/a/12643073/190597
"""
return [ atof(c) for c in re.split(r"[+-]?([0-9]+(?:[.][0-9]*)?|[.][0-9]+)", text) ]

alist=[
"something1",
"something2",
"something1.0",
"something1.25",
"something1.105"]

alist.sort(key=natural_keys)
print(alist)
``````

yields

``````["something1", "something1.0", "something1.105", "something1.25", "something2"]
``````

You"ll want to use the `isdigit` method on your `str` object:

``````if len(isbn) == 10 and isbn.isdigit():
``````

From the `isdigit` documentation:

str.isdigit()

Return True if all characters in the string are digits and there is at least one character, False otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.