95 of 151 menu

The isnumeric method

The isnumeric method checks whether a string contains only numbers. Unlike the isdigit method, the isnumeric method checks whether a string contains all types of numeric values, including Roman numerals and fractions.

Nothing is passed to the method parameters. The method returns the Boolean values ​​True or False.

Syntax

string.isnumeric()

Example

Let's check that the string consists only of numbers:

txt = '12345' print(txt.isnumeric())

Result of code execution:

True

Example

Now let's say there are other symbols in the line:

txt = '12345ab' print(txt.isdigit())

Result of code execution:

False

Example

Now let's check a string containing Roman numerals using two methods isnumeric and isdigit:

txt = 'Ⅻ' print('isdigit:', txt.isdigit()) print('isnumeric:', txt.isnumeric())

Result of code execution:

'isdigit:' False 'isnumeric:' True

Example

Let's check if a string contains a fractional number using the isnumeric and isdigit methods:

txt = '⅓' print('isdigit:', txt.isdigit()) print('isnumeric:', txt.isnumeric())

Result of code execution:

'isdigit:' False 'isnumeric:' True

See also

  • method isdigit,
    which checks if a string contains only numbers
  • method isalnum,
    which checks if a string contains letters and numbers
  • method isalpha,
    which checks if a string contains only letters
  • method isspace,
    which checks if a string contains only spaces
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline