2016-08-29 19 views

回答

6

你所要求的是一個str.isalpha()功能:

isalpha(...) 
    S.isalpha() -> bool 

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

例如,你可以使用它像這樣:

def ask_name(): 
    while True: 
     name = raw_input("What is your name?") 
     if name.isalpha(): 
      return name 
     else: 
      print("Please use only letters, try again") 
相關問題