Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Python String isdecimal()

$
0
0

python String isdecimal() function returns True if all the characters in the string are decimal characters, otherwise False. If the string is empty then this function returns False.


Python String isdecimal()
Python String isdecimal()

If a character can be used to form a number in base 10, then it’s considered as decimal character. For example, (U+0660, ARABIC-INDIC DIGIT ZERO) and (U+1D7DC, MATHEMATICAL DOUBLE-STRUCK DIGIT FOUR) are also treated as decimal characters.

Let’s look at some of the examples of isdecimal() function.

Copy

s = '100' print(s.isdecimal())

Output: True because all the characters in the string are decimals.

Copy

s = '0xF' print(s.isdecimal())

Output: False because the string characters are not decimal and can’t be used to represent a number in base 10.

Copy

s = '10.55' print(s.isdecimal())

Output: False because dot character is not a decimal character.

Copy

s = '' print(s.isdecimal())

Output: False because string is empty.

Copy

s = '12 ' # U+0660, U+1D7DC print(s.isdecimal()) print(int(s))

Output:

Copy

True 1024

You can checkout more Python examples from our GitHub Repository .

Reference: Official Documentation


Viewing all articles
Browse latest Browse all 9596

Trending Articles