def func(a,b): res=a+b print(res)#只能看結果,但不能用 def func2(a,b): res=a+b return res #可以用 def get_user(): s='abc,123' username,password=s.split(',') return username,password #可被其他函數調用,可return多個值用逗號分開,可用一個變量來接收 res=get_user() print(res)# 可用一個變量來接收 ('abc', '123') def login(): for i in range(3): username,password=get_user() user=input('username:') pwd=input('password:') if username==user and password==pwd: print("登錄成功") return else: print("賬號密碼錯誤")
return的參數值可以被其他函數調用
print只能打印函數的結果,這些結果只能看,不能被其他函數調用
更多,請參考 https://www.jianshu.com/p/18a6c0c76438
