“Python Sprawdź, czy ciąg jest pływakiem” Kod odpowiedzi

Python jest pływakiem

def is_number(x):
    '''
        Takes a word and checks if Number (Integer or Float).
    '''
    try:
        # only integers and float converts safely
        num = float(x)
        return True
    except ValueError as e: # not convertable to float
        return False
Poised Pygmy

Sprawdź, czy sznur to pływak Python

try:
    float(element)
except ValueError:
    print "Not a float"
Cozy Dev

Python Sprawdź, czy ciąg jest pływakiem

def isfloat(num):
    try:
        float(num)
        return True
    except ValueError:
        return False

print(isfloat('s12'))
print(isfloat('1.123'))
Wojak's distant cousin

Odpowiedzi podobne do “Python Sprawdź, czy ciąg jest pływakiem”

Pytania podobne do “Python Sprawdź, czy ciąg jest pływakiem”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu