# 定义一个方法 无参数 做一件事情 就是打印一下def print_hello():print("hello")print_hello() # 调用方法# 定义一个有参数的方法def print_hello1(username):print(username)print_hello1("name")# 定义一个有参数默认值的方法def print_hello2(username='tom'):print(username)print_hello2()# 定义一个有返回值的方法def print_hello3(username='tom'):return usernameobj = print_hello3("你猜猜我猜不猜")print(obj)# 定义一个接受List的方法 并传入副本进行操作def listValues(List):if isinstance(List, list):for v in List:print(v)listsdemo = [0, 1, 2, 3, 4, 5, 6]listValues(listsdemo[:])print(listsdemo)# 传递任意参数的实参def print_more(*names):for name in names:print(name)print_more("hello ", "world", 1, 2, 3, 4)# 传递任意参数的实参和固定参数def print_more2(age, *names):print(age)for name in names:print(name)print_more2(19999, "hello ", "world", 1, 2, 3, 4)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。