python函数

1.def

2.函数名

3.函数体

4.返回值

5.参数

 形参为带一个星的:

形参为带两个星的:

利用动态参数实现format功能:

 

python 中str.format函数的定义:format(*args,**kargs)

 全局变量:

 

 testfunc.py

 1 def login(username, password):
 2     """
 3     用于登录
 4     :param username:
 5     :param password:
 6     :return:
 7     """
 8     f=open("db", "r")
 9     for line in f:
10         line_list=line.split("|")
11         if line_list[0] == username and line_list[1] == password:
12             return True
13     return False
14 
15 
16 def main():
17     t = input("1:login;2:register")
18     if t == "1":
19         user = input("please enter the username")
20         pwd = input("please input password")
21         r = login(user, pwd)
22         if r:
23             print("success")
24         else:
25             print("fail")
26 
27 main()
testfunc.py

原文地址:https://www.cnblogs.com/gpdm/p/6421548.html