博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 2 3 4 5 6 7 8 ··· 13 下一页

2019年2月27日

摘要: map函数 :处理序列中的每个元素,得到的结果是一个列表,该列表元素个数及位置与原来一样## 求列表里元素的平方 (原始方法) num_1=[1,2,13,5,8,9] res =[] for i in num_1: res.append(i**2) print('打印结果:',res) 打印结果: 阅读全文

posted @ 2019-02-27 10:02 MJ-majun 阅读(150) 评论(0) 推荐(0) 编辑

2019年2月25日

摘要: # 函数式(方程式 y = 2*x+1) def calc(x): return 2*x+1 print('得出的结果:',calc(6)) 得出的结果: 13 # 面向过程 def calc(x): res = 2*x res +=1 return res print('得出的结果是:',calc(6)) 得出的结果是: 13 高阶函数--------... 阅读全文

posted @ 2019-02-25 17:48 MJ-majun 阅读(92) 评论(0) 推荐(0) 编辑

摘要: # 匿名函数 lamdba name = 'xiaoma' f = lambda x:x+'jun' res = f(name) print('匿名函数的运行结果:',res) 匿名函数的运行结果: xiaomajun func = lambda x,y,z:x+y+z res = func(10, 阅读全文

posted @ 2019-02-25 15:42 MJ-majun 阅读(216) 评论(0) 推荐(0) 编辑

2019年2月24日

摘要: def test1(): print('in the test1') def test(): print('in the test') return test1 print(test) res = test() print(res()) in the test in the test1 None def foo(): name = 'majun' ... 阅读全文

posted @ 2019-02-24 22:48 MJ-majun 阅读(192) 评论(0) 推荐(0) 编辑

摘要: # 递归 def calc(n): print(n) if int(n/2) == 0: return n res = calc(int(n/2)) return res res = calc(10) print(res) 10 5 2 1 1 import time person_list = [ 阅读全文

posted @ 2019-02-24 21:57 MJ-majun 阅读(140) 评论(0) 推荐(0) 编辑

摘要: # 风湿理论之函数即变量 def foo(): print('from foo') bar() def bar(): print('from bar') foo() from foo from bar def bar(): print('from bar') def foo(): print('from foo') bar() foo() f... 阅读全文

posted @ 2019-02-24 16:37 MJ-majun 阅读(107) 评论(0) 推荐(0) 编辑

摘要: # 全局变量 如果函数的内容无 global关键字,优先读取全局变量,无法对全局变量重新赋值, name = 'mj' def change_name(): print('change_name',name) change_name() change_name mj # 但是对于可变类型,可以对内部 阅读全文

posted @ 2019-02-24 11:33 MJ-majun 阅读(109) 评论(0) 推荐(0) 编辑

2019年2月23日

摘要: # format() 方法 {}代替元素 默认是从左往右开始取值 test = 'i am {},age {},{}'.format('xiaoma',18,'happy') print(test) i am xiaoma,age 18,happy test1 = 'i am {1},age {0} 阅读全文

posted @ 2019-02-23 18:22 MJ-majun 阅读(259) 评论(0) 推荐(0) 编辑

摘要: #### 字符串格式化。 # %s 代替任何的元素 (数字,字符串,列表··) print('I live %s crty' %'my') print('I live %s crty' %'[6,8,9]') I live my crty I live [6,8,9] crty # %s -- %( 阅读全文

posted @ 2019-02-23 11:55 MJ-majun 阅读(186) 评论(0) 推荐(0) 编辑

2019年2月22日

摘要: # 集合是由 { ,} 组成 test = {1,2,8,9,7,5} print(test) {1, 2, 5, 7, 8, 9} # 集合的结果是 去重的,且排序是 无序的 test = {1,2,3,3,5,8,5,9,7,6} print(test) {1, 2, 3, 5, 6, 7, 8 阅读全文

posted @ 2019-02-22 10:49 MJ-majun 阅读(148) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 ··· 13 下一页