上一页 1 ··· 345 346 347 348 349 350 351 352 353 ··· 403 下一页
摘要: 1、原始函数 def a(x,y): while x: temp = x.pop() print(f"printing model:{temp}") y.append(temp) def b(x): print("\nThe following model had been printed!") f 阅读全文
posted @ 2021-03-10 17:38 小鲨鱼2018 阅读(276) 评论(0) 推荐(0)
摘要: 1、不使用函数: list1 = ["aaaa","bbbb","cccc"] list2 = [] while list1: temp = list1.pop() print(f"printing model {temp}") list2.append(temp) print("\nThe fol 阅读全文
posted @ 2021-03-10 16:52 小鲨鱼2018 阅读(266) 评论(0) 推荐(0)
摘要: 1、 python中向函数传递列表,提高处理列表的效率。 >>> def a(x): ## 定义函数的形参x为可迭代对象 for i in x: print(f"hello,{i.title()}") >>> b = ["aaa","bbb","ccc","ddd"] ## 实参定义为列表,实现向函 阅读全文
posted @ 2021-03-10 15:22 小鲨鱼2018 阅读(487) 评论(0) 推荐(0)
摘要: 1、 >>> def a(first,meddle,last): b = f"{first} {meddle} {last}" return b.title() >>> a("aaa","bbb","ccc") 'Aaa Bbb Ccc' >>> a("aaa","bbb") ## 少一个实参报错 阅读全文
posted @ 2021-03-10 11:26 小鲨鱼2018 阅读(71) 评论(0) 推荐(0)
摘要: 1、 >>> def a(x,y): b = {"key1":x,"key2":y} return b >>> a(111,222) {'key1': 111, 'key2': 222} >>> a(111,222,333) ## 多家实参报错 Traceback (most recent call 阅读全文
posted @ 2021-03-10 11:12 小鲨鱼2018 阅读(378) 评论(0) 推荐(0)
摘要: 1、 def a(first,last): full = f"{first} {last}" return full.title() while True: ## 条件为真的话,一直循环 print("\n\nplease tell me your name:") ## 两个\n,每执行一次循环,空 阅读全文
posted @ 2021-03-10 10:33 小鲨鱼2018 阅读(363) 评论(0) 推荐(0)
摘要: python中函数可以返回任何类型的值,包含列表和字典等较复杂的数据结构。 1、 >>> def fun(first,last,age): full = {"first":first,"last":last,"age":age} ## 函数返回列表 return full >>> infor = f 阅读全文
posted @ 2021-03-09 22:46 小鲨鱼2018 阅读(2356) 评论(0) 推荐(0)
摘要: 1、 >>> def a(first,middle,last): ## 函数定义了三个形参 full = f"{first} {middle} {last}" return full.title() >>> name = a("aaa","bbb","ccc") >>> print(name) Aa 阅读全文
posted @ 2021-03-09 22:11 小鲨鱼2018 阅读(159) 评论(0) 推荐(0)
摘要: 1、 >>> def a(x,y,z): print(x + y + z) >>> a(2,3,4) 9 >>> a(2,3) ## 缺少对应的实参 Traceback (most recent call last): File "<pyshell#317>", line 1, in <module 阅读全文
posted @ 2021-03-09 11:40 小鲨鱼2018 阅读(94) 评论(0) 推荐(0)
摘要: 1、 >>> def a(x,y): """ function: sum author: xxxx date: 2021:03:08 """ print(x + y) >>> a(10,8) 18 >>> print(a.__doc__) ## 获取函数文档 function: sum author 阅读全文
posted @ 2021-03-08 22:39 小鲨鱼2018 阅读(250) 评论(0) 推荐(0)
上一页 1 ··· 345 346 347 348 349 350 351 352 353 ··· 403 下一页