如何限制输入的字符类型python

How to limit the type of characters input python

如何限制可以输入的字符数和字符类型。

s = input('What is your number)

一个数字只能是 9 位数字所以它应该被限制在 9 位数字并且只能是数字

x = input('what is your email address)

电子邮件地址最少可以包含 8 个字符,最多可以包含 60 个字符,并且还必须包含 @ 符号。

我该怎么做?

其实亲爱的,你不能限制输入功能,但是你可以通过这种方式实现你想要的:

def isnumber(s):
    if s.isdigit() and len(s) <= 9:
        return True
    else:
        print('you should input number and length less than 9')
        return False

def main():
    s = input('What is your number')
    while not isnumber(s):
        s = input('What is your number')
    print("your number is", s)


if __name__ == "__main__":
    main()