Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这个函数询问名字
def printName(): print("Enter your name: ") n=input() printName()
if 语句检查 n 是否等于 Python
if n=="Python": print("Welcome") else: print("Try again")
n仅在函数内部定义。这应该有效:
n
def printName(): print("Enter your name: ") n=input() if n=='Python': ...
或者,您也可以这样做:
def printName(): print("Enter your name: ") n=input() return n n = printName() # now you can use n