Python之定义函数

一、函数的写法:

#语法
def 函数名(参数1,参数2,参数3,...):
    '''注释'''
    函数体
    return 返回的值

#函数名要能反映其意义
 1 def auth(user:str,password:str)->int:
 2     '''
 3     auth function
 4     :param user: 用户名
 5     :param password: 密码
 6     :return: 认证结果
 7     '''
 8     if user == 'george' and password == '123':
 9         return 1
10 # print(auth.__annotations__) #{'user': <class 'str'>, 'password': <class 'str'>, 'return': <class 'int'>}
11 
12 user=input('用户名>>: ').strip()
13 pwd=input('密码>>: ').strip()
14 res=auth(user,pwd)
15 print(res)
例子

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-11-19
  • 2022-12-23
  • 2021-11-23
  • 2021-05-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2021-04-29
  • 2021-12-22
  • 2021-09-28
  • 2022-12-23
相关资源
相似解决方案