logo

Python String isnumeric() Metod

Pytonorm isnumeric() metod kontrollerar om alla tecken i strängen är numeriska tecken eller inte. Den returnerar True om alla tecken är sanna, annars returneras False.

Numeriska tecken inkluderar siffror och alla tecken som har egenskapen Unicode numeriskt värde.

Signatur

 isnumeric() 

Parametrar

Ingen parameter krävs.

Lämna tillbaka

Det returnerar antingen True eller False.

Låt oss se några exempel på isnumeric()-metoden för att förstå dess funktioner.

Python String isnumeric() Metodexempel 1

Här skapas ett enkelt exempel för att kontrollera att strängen är numerisk eller inte.

 # Python isnumeric() method example # Variable declaration str = '12345' # Calling function str2 = str.isnumeric() # Displaying result print(str2) 

Produktion:

 True 

Python String isnumeric() Metodexempel 2

Låt oss testa det på den icke-numeriska strängen, se att den returnerar False.

 # Python isnumeric() method example # Variable declaration str = 'javatpoint12345' # Calling function str2 = str.isnumeric() # Displaying result print(str2) 

Produktion:

 False 

Python String isnumeric() Metodexempel 3

Se ett senario var och hur vi kan tillämpa isnumeric()-metoden i python-programmering

 # Python isnumeric() method example str = '123452500' # True if str.isnumeric() == True: print('Numeric') else: print('Not numeric') str2 = '123-4525-00' # False if str2.isnumeric() == True: print('Numeric') else: print('Not numeric') 

Produktion:

 Numeric Not numeric