что не так с этой функцией python [duplicate]

Важно не атрибут, а свойство , и его значение является логическим.

Вы можете установить его с помощью

 document.getElementById("edName").required = true;
5
задан Ashwini Chaudhary 3 July 2013 в 19:50
поделиться

3 ответа

Вы можете использовать str.isdigit и str.isalpha:

if a.isalpha():
   #do something
elif a.isdigit():
   #do something

help на str.isdigit:

>>> print str.isdigit.__doc__
S.isdigit() -> bool

Return True if all characters in S are digits
and there is at least one character in S, False otherwise.

help на str.isalpha:

>>> print str.isalpha.__doc__
S.isalpha() -> bool

Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.
15
ответ дан Ashwini Chaudhary 18 August 2018 в 11:20
поделиться

Вы можете использовать a.isalpha (), a.isdigit (), a.isalnum (), чтобы проверить, состоит ли из букв, цифр или комбинации чисел и букв соответственно.

if a.isalpha(): # a is made up of only letters
    do this

if a.isdigit(): # a is made up of only numbers
    do this

if a.isalnum(): # a is made up numbers and letters
    do this

Python docs расскажет вам более подробно о методах, которые вы можете вызвать для строк.

3
ответ дан jh314 18 August 2018 в 11:20
поделиться

Видите, что вы используете input () в примере тура, вы должны знать, что вход всегда дает вам строку. И вам нужно направить его на правильный тип: EG: Int или Float.

def isint(input):
    return input.isdigit()

def isfloat(input):
    try: 
        return float(input) != None;
    except ValueError: 
        return False;

def isstr(input):
    if not isint(input) and not isfloat(input):
        return True
    return False

print isint("3.14")
print isfloat("3.14")
print isstr("3.14")
0
ответ дан JHolta 18 August 2018 в 11:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: