20180729    补充部分代码

20180727    上传代码

  1. #!/usr/bin/env python
  2. # -*- coding:utf-8 -*-
  3. # ********************day16_函数作用域_匿名函数_函数式编程_map_reduce_filter_内置函数(部分)*******************
  4. # # 1、全局变量与局部变量
  5. # # 2、全局变量与局部变量 nonlocal
  6. # # 3、函数里头调用函数
  7. # # 4、返回函数中的子函数
  8. # # 5、多级函数体的套用
  9. # # 6、函数()()()...()
  10. # # 7、匿名函数lambda
  11. # # 8、编程的方法论:(关于解释,可能不太正确,需要后期补充知识再来修正)
  12. # # # 1、面向过程编程
  13. # # # 功能的实现,是一步一步分步骤实现
  14. # # # 2、函数式
  15. # # # 通过函数的方式实现功能,函数式实现过程中,只允许输入的时候有信息输入,函数体的实现过程中,不允许有
  16. # # # 定义内容等
  17. # # # 3、面向对象编程
  18. # # # ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===>
  19. # # # ===>特点:
  20. # # # 面向过程:根据业务逻辑从上到下写垒代码
  21. # # # 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可
  22. # # # 面向对象:对函数进行分类和封装,让开发“更快更好更强...”
  23. # # # 函数式编程: 易读性相对较差
  24. # # # 过程式编程: 易读性相对较高
  25. # # # y = 2*x + 1
  26. # # # 函数式编程( 但这个例子不是非常准确,只用于理解 )
  27. # # # 函数式编程语言: Hashell clean; erlang
  28. # # # 函数式编程
  29. # # #
  30. # # # 1.不可变数据
  31. # # #
  32. # # # 2.第一类对象:函数即为变量
  33. # # #
  34. # # # 3.尾调用优化(尾递归)
  35. # # # Python中的函数与变量 - Python少年 - 博客园
  36. # # # https://www.cnblogs.com/echoboy/p/8973266.html
  37. # # 9、高阶函数(含有其下至少一种特性的函数)
  38. # # # # 1、把函数当作参数传给另外一个参数
  39. # # # # 2、返回值中包含函数
  40. # # # ===>通俗讲,就是把某一个函数体,放在,另外一个函数体的“入口”,或者出口的位置
  41. # # # # 把函数当作参数传给另外一个参数
  42. # # 10、返回值中包含函数
  43. # # 11、返回值中包含函数
  44. # # # # 返回的也可以是函数体的体身内容,注意返回的是“”“”函数的地址“”“”
  45. # # 12、求平方
  46. # # 13、过程式编程
  47. # # 14、对象式编程,函数体实现
  48. # # 15、使用内置函数 map(功能,处理内容)
  49. # # # # 关于map使用的注意事项:
  50. # # # # map返回的是一个迭代器,如果使用for进行输出的话,那么for运行结束后,迭代器的内容就全部输出完毕,
  51. # # # # =====》变为空
  52. # # 16、filter(功能,内容)
  53. # # filter的第一个参数为真,就保留结果, 因此要过滤掉参数中含有开始为“sb”的内容,应该在lambda中加入not
  54. # # 17、map reduce filter总结
  55. # # # reduce() 函数会对参数序列中元素进行累积。
  56. # # # 函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给 reduce 中的函数 function
  57. # # # (有两个参数)先对集合中的第 1、2 个元素进行操作,得到的结果再与第三个数据用 function 函数运算,
  58. # # # 最后得到一个结果。
  59. # # # reduce 函数 实现上述的功能
  60. # # 18、关于reduce的求和实例
  61. # # # # reduce: 处理一个序列,然后把序列进行合并
  62. # # 19、abs() 函数返回数字的绝对值。
  63. # # 20、all
  64. # # # all() 函数用于判断给定的可迭代参数 iterable 中的所有元素是否 都为 TRUE ,如果是返回 True,否则返回 False。
  65. # # # 元素除了是 0、空、FALSE 外都算 TRUE。
  66. # # 21、any()
  67. # # # # any() 函数用于判断给定的可迭代参数 iterable 是否 全部为 Fals e,则返回 False,如果有一个为 True,则返回 True。
  68. # # # # 元素除了是 0、空、FALSE ,None 外都算 TRUE。
  69. # # 22、bin
  70. # # # bin() 返回一个整数 int 或者长整数 long int 的二进制表示。
  71. # # 23、bool
  72. # # # # bool() 函数用于将给定参数转换为布尔类型,如果没有参数,返回 False。
  73. # # 24、bytes
  74. # # # 描述c
  75. # # # bytes 函数返回一个新的 bytes 对象,该对象是一个 0 <= x < 256 区间内的整数不可变序列。它是 bytearray 的不可变版本。
  76. # # #
  77. # # # 语法 #
  78. # # # 以下是 bytes 的语法:
  79. # # # class bytes([source[, encoding[, errors]]])
  80. # # # 参数 #
  81. # # # 如果 source 为整数,则返回一个长度为 source 的初始化数组;
  82. # # # 如果 source 为字符串,则按照指定的 encoding 将字符串转换为字节序列;
  83. # # # 如果 source 为可迭代类型,则元素必须为[0 ,255] 中的整数;
  84. # # # 如果 source 为与 buffer 接口一致的对象,则此对象也可以被用于初始化 bytearray。
  85. # # # 如果没有输入任何参数,默认就是初始化数组为0个元素。
  86. # # 25、encoding decode 编码与解码
  87. # # 26、chr
  88. # # 27、dir()
  89. # # # dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。
  90. # # # 如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。
  91. # # #
  92. # # 28、divmod
  93. # # # python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。
  94. # # # 在 python 2.3 版本之前不允许处理复数。
  95. # # #
  96. # # # 函数语法
  97. # # # divmod(a, b)
  98. # # #
  99. # # # 参数说明:
  100. # # # a: 数字
  101. # # # b: 数字
  102. # # # 关于应用实例说明,求出的 整数+余数 能够应用于搜索页面的显示。如百度搜索“信息a”,10条,一页3条
  103. # # # 那么,divmod(10 , 3)==> (3, 1) ,就是说,显示需要3页+1条, 那么结果应该,显示4页
  104. # # 29、str与字典
  105. # # 30、eval()
  106. # # # =====> 下列的应用,实际上就是去掉字符串两边的 “ "" ”符号,返回里头的表达式
  107. # # # =====> 也就是把字符串中的数据结构给提取出来
  108. # # # 描述
  109. # # # eval() 函数用来执行一个字符串表达式,并返回表达式的值。
  110. # # #
  111. # # # 语法
  112. # # # 以下是 eval() 方法的语法:
  113. # # #
  114. # # # eval(expression[, globals[, locals]])
  115. # # # 参数
  116. # # # expression -- 表达式。
  117. # # # globals -- 变量作用域,全局命名空间,如果被提供,则必须是一个字典对象。
  118. # # # locals -- 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。
  119. # # # 返回值
  120. # # # 返回表达式计算结果。
  121. # # 31、hash
  122. # # # 可hash的数据类型即不可变数据类型,
  123. # # # 不可hash的数据类型即 可变数据类型
  124. # #
  125. # # 32、help()
  126. # # # # 打印帮助
  127. # # 33、bin oct hex
  128. # # # # bin 十进制===》 二进制
  129. # # # # oct 十进制===》 8进制
  130. # # # # hex 十进制 ==>十六进制
  131. # # 34、isinstance()
  132. # # # # 描述
  133. # # # # isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
  134. # # # # isinstance() 与 type() 区别:
  135. # # # # type() 不会认为子类是一种父类类型,不考虑继承关系。
  136. # # # # isinstance() 会认为子类是一种父类类型,考虑继承关系。
  137. # # # #
  138. # # # # 如果要判断两个类型是否相同推荐使用 isinstance()。
  139. # # 35、globals
  140. # # # globals() 函数会以字典类型返回当前位置的全部全局变量。
  141. # # # 参数
  142. # # # 无
  143. # # # 返回值
  144. # # # 返回全局变量的字典。
  145. # # 36、locals
  146. # # # 描述
  147. # # # locals() 函数会以字典类型返回当前位置的全部局部变量。
  148. # # # 对于函数, 方法, lambda 函式, 类, 以及实现了 __call__ 方法的类实例, 它都返回 True。
  149. # # #
  150. # # 37、min max
  151. # # # min 求最小值
  152. # # # max 求最大值
  153. # print("分割线".center(80,"*"))
  154. # **************************************分割线***************************************
  155. # **************************************分割线***************************************
  156. # **************************************分割线***************************************
  157. # # 1、全局变量与局部变量
  158. # name = "alex"
  159. # def chang_name():
  160. # # name = "lhf"
  161. # # print(name)
  162. # global name
  163. # name = "ccc"
  164. # print(name)
  165. #
  166. # def foo():
  167. # name = "foo!!"
  168. # print(name)
  169. # foo()
  170. #
  171. # print(name)
  172. # chang_name()
  173. # print(name)
  174. #
  175. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  176. # # alex
  177. # # ccc
  178. # # foo!!
  179. # # ccc
  180. # #
  181. # # Process finished with exit code 0
  182. #
  183. # # 2、全局变量与局部变量 nonlocal
  184. # name = "alex"
  185. #
  186. # def chang_name():
  187. # # name = "lhf"
  188. # # print(name)
  189. # # global name
  190. # name = "ccc"
  191. # print(name)
  192. #
  193. # def foo():
  194. # nonlocal name
  195. # name = "foo!!"
  196. # print(name)
  197. #
  198. # foo()
  199. # print("after foo: ",name)
  200. #
  201. #
  202. # print("start: ",name)
  203. # chang_name()
  204. # print("end: ",name)
  205. #
  206. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  207. # # start: alex
  208. # # ccc
  209. # # foo!!
  210. # # after foo: foo!!
  211. # # end: alex
  212. # #
  213. # # Process finished with exit code 0
  214. # 02 03
  215. # 02 03
  216. # 02 03
  217. # 02 03
  218. # # 3、函数里头调用函数
  219. # name = "alex"
  220. #
  221. # def foo():
  222. # name = "linhaifeng"
  223. # def bar():
  224. # print(name)
  225. #
  226. # bar()
  227. #
  228. # foo()
  229. #
  230. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  231. # # linhaifeng
  232. # #
  233. # # Process finished with exit code 0
  234. #
  235. # # 4、返回函数中的子函数
  236. # name = "alex"
  237. #
  238. # def foo():
  239. # name = "linhaifeng"
  240. # def bar():
  241. # print(name)
  242. # return 0 # 0会被打印出来》 print(a)中实现
  243. # return bar() # 带括号, 表示
  244. # # 返回整个函数体, bar() 函数 会被运行
  245. # # return bar # 不带括号,表示返回整个函数体的内存地址,bar() 函数不会被运行
  246. # # a = foo #这个返回的foo的函数内存地址
  247. # a = foo()
  248. # print(a)
  249. #
  250. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  251. # # linhaifeng
  252. # # 0
  253. # #
  254. # # Process finished with exit code 0
  255. # # 5、多级函数体的套用
  256. # # 6、函数()()()...()
  257. # name = "alex"
  258. #
  259. # def foo():
  260. # name = "linhaifeng"
  261. # def bar():
  262. # name = "bar"
  263. # def tt():
  264. # print(name)
  265. # return tt
  266. # return bar # 带括号, 表示返回整个函数体, bar() 函数 会被运行
  267. # # return bar # 不带括号,表示返回整个函数体的内存地址,bar() 函数不会被运行
  268. #
  269. #
  270. # bar = foo()
  271. # tt = bar()
  272. # print("print(\"tt: \" ,tt)".center(60,"*"))
  273. # print("tt: " ,tt) # tt的地址
  274. #
  275. # print("print(\"tt(): \" ,tt())".center(60,"*"))
  276. # print("tt(): ",tt()) # 对tt进行运行,并且打印tt的返回值,默认None
  277. #
  278. # print("tt()".center(60,"*"))
  279. # tt() # 对tt进行运行
  280. #
  281. # print("另外一种运行 tt的方式".center(60,"-"))
  282. # # 另外一种运行 tt的方式
  283. # foo()()()
  284. #
  285. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  286. # # ********************print("tt: " ,tt)********************
  287. # # tt: <function foo.<locals>.bar.<locals>.tt at 0x00000000039EE7B8>
  288. # # ******************print("tt(): " ,tt())******************
  289. # # bar
  290. # # tt(): None
  291. # # ****************************tt()****************************
  292. # # bar
  293. # # ------------------------另外一种运行 tt的方式------------------------
  294. # # bar
  295. # #
  296. # # Process finished with exit code 0
  297. # #
  298. # # 04 05
  299. # # 04 05
  300. # # 04 05
  301. # # 04 05
  302. #
  303. # # 7、匿名函数
  304. # # lambda x: x+1
  305. # # 等同于下面的函数
  306. # def calc(x):
  307. # return x+1
  308. # res = calc(10)
  309. # print("res:",res)
  310. # print("calc:",calc) # 直接打印函数 calc的地址
  311. #
  312. # print("lambda x:x+1 :",lambda x:x+1)
  313. # func = lambda x:x+1
  314. # print("func(10): ",func(10)) # 等同于(lambda x:x+1)(10)
  315. #
  316. # # func1(10) = lambda x:x+1 #=======> 没有这种用法 ,报错
  317. #
  318. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  319. # # res: 11
  320. # # calc: <function calc at 0x00000000003C1EA0>
  321. # # lambda x:x+1 : <function <lambda> at 0x0000000002974620>
  322. # # func(10): 11
  323. # #
  324. # # Process finished with exit code 0
  325. # # 匿名函数演示2
  326. # # 一般函数体的使用
  327. # name = "alex"
  328. # def change_name(x):
  329. # return x + "--->sb"
  330. #
  331. # res = change_name(name)
  332. # print(res)
  333. #
  334. # # 匿名函数
  335. # func = lambda x: x + "--->sb"
  336. # ni = func("who is ")
  337. # print(func("YouAre"))
  338. # print(ni)
  339. #
  340. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  341. # # alex--->sb
  342. # # YouAre--->sb
  343. # # who is --->sb
  344. # #
  345. # # Process finished with exit code 0
  346. # 匿名函数 多组数据
  347. # 一般实现
  348. # def test(x,y,z):
  349. # return x+1,y+"y",z+"+_+?"
  350. #
  351. # print(test(1,"2","3"))
  352. #
  353. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  354. # # (2, '2y', '3+_+?')
  355. # #
  356. # # Process finished with exit code 0
  357. # # 匿名实现
  358. #
  359. # func = lambda x,y,z: (x+1,y+"y",z+"+_+?")
  360. # print(func(1,"2","3"))
  361. #
  362. # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  363. # (2, '2y', '3+_+?')
  364. #
  365. # Process finished with exit code 0
  366. # 06
  367. # 06
  368. # 06
  369. # # 8、编程的方法论:(关于解释,可能不太正确,需要后期补充知识再来修正)
  370. # 1、面向过程编程
  371. # 功能的实现,是一步一步分步骤实现
  372. # 2、函数式
  373. # 通过函数的方式实现功能,函数式实现过程中,只允许输入的时候有信息输入,函数体的实现过程中,不允许有
  374. # 定义内容等
  375. # 3、面向对象编程
  376. # ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===> ===>
  377. # ===>特点:
  378. # 面向过程:根据业务逻辑从上到下写垒代码
  379. # 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可
  380. # 面向对象:对函数进行分类和封装,让开发“更快更好更强...”
  381. # 函数式编程: 易读性相对较差
  382. # 过程式编程: 易读性相对较高
  383. # y = 2*x + 1
  384. # 函数式编程( 但这个例子不是非常准确,只用于理解 )
  385. # 函数式编程语言: Hashell clean; erlang
  386. # 函数式编程
  387. #
  388. # 1.不可变数据
  389. #
  390. # 2.第一类对象:函数即为变量
  391. #
  392. # 3.尾调用优化(尾递归)
  393. # Python中的函数与变量 - Python少年 - 博客园
  394. # https://www.cnblogs.com/echoboy/p/8973266.html
  395. #
  396. # def cal(x) :
  397. # return 2*x + 1
  398. #
  399. # # 过程式编程
  400. # def cal(x) :
  401. # res =2*x
  402. # res +=1
  403. # return res
  404. #
  405. # ***************************函数式编程****************************
  406. # ***************************函数式编程****************************
  407. # ***************************函数式编程****************************
  408. # # 9、高阶函数(含有其下至少一种特性的函数)
  409. # # 1、把函数当作参数传给另外一个参数
  410. # # 2、返回值中包含函数
  411. # ===>通俗讲,就是把某一个函数体,放在,另外一个函数体的“入口”,或者出口的位置
  412. # # 把函数当作参数传给另外一个参数
  413. # def foo(n) : # n = bar
  414. # print(n) # bar 的返回值是 None
  415. #
  416. # def bar(name):
  417. # print("my name is %s" %name)
  418. #
  419. # print("foo(bar): ")
  420. # foo(bar)
  421. #
  422. # print("foo(bar() ): ")
  423. # foo(bar("bar here"))
  424. #
  425. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  426. # # foo(bar):
  427. # # <function bar at 0x0000000002974620>
  428. # # foo(bar() ):
  429. # # my name is bar here
  430. # # None
  431. # #
  432. # # Process finished with exit code 0
  433. # # 10、返回值中包含函数
  434. # def bar():
  435. # print("from bar")
  436. # def foo():
  437. # print("from foo")
  438. # return bar
  439. #
  440. # n = foo()
  441. # n()
  442. # print("n: ",n )
  443. # print("n(): ",n())
  444. #
  445. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  446. # # from foo
  447. # # from bar
  448. # # n: <function bar at 0x00000000004D1EA0>
  449. # # from bar
  450. # # n(): None
  451. # #
  452. # # Process finished with exit code 0
  453. # # 11、返回值中包含函数
  454. # # 返回的也可以是函数体的体身内容,注意返回的是“”“”函数的地址“”“”
  455. #
  456. #
  457. # def handle():
  458. # print("from handle")
  459. # return handle
  460. #
  461. # h = handle()
  462. # h()
  463. #
  464. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  465. # # from handle
  466. # # from handle
  467. # #
  468. # # Process finished with exit code 0
  469. # 08
  470. # 08
  471. # 08
  472. # print("day16_08 map函数".center(80,"*"))
  473. # ********************************day16_08 map函数*********************************
  474. # ********************************day16_08 map函数*********************************
  475. # ********************************day16_08 map函数*********************************
  476. # # 12、求平方
  477. # # 13、过程式编程
  478. # num_1 = [1,2,3,5,7,10]
  479. # # num_2 = [1,2,3,5,7,10]
  480. #
  481. # ret = []
  482. # for i in num_1:
  483. # ret.append(i**2)
  484. # print(ret)
  485. #
  486. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  487. # # [1, 4, 9, 25, 49, 100]
  488. # #
  489. # # Process finished with exit code 0
  490. # # 14、对象式编程,函数体实现
  491. # num_1 = [1,2,3,5,7,10]
  492. #
  493. # def map_test(array):
  494. # ret = []
  495. # for i in array:
  496. # ret.append(i**2)
  497. # return ret
  498. #
  499. # print( map_test( num_1))
  500. #
  501. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  502. # # [1, 4, 9, 25, 49, 100]
  503. # #
  504. # # Process finished with exit code 0
  505. # num_1 = [1,2,3,5,7,10]
  506. #
  507. # def reduce_one(x):
  508. # return x-1
  509. # def add_one(x):
  510. # return x+1
  511. # def square_itself(x):
  512. # return x**2
  513. # def map_test(func,array):
  514. # #func 实现方法程序的地址
  515. # #array 传入数组或者列表
  516. # ret = []
  517. # for i in array:
  518. # # 实现某功能的方法
  519. # # ret.append(i**2) # 求平方方法
  520. # res = func(i) # 写成一个步骤就是 ret.append( func(i) )
  521. # ret.append( res ) # 写成一个步骤就是 ret.append( func(i) )
  522. # return ret
  523. #
  524. # print( "map_test( square_itself,num_1):")
  525. # print( map_test( square_itself,num_1) )
  526. # print( "map_test( add_one,num_1) :")
  527. # print( map_test( add_one,num_1) )
  528. # print( "map_test( reduce_one,num_1):")
  529. # print( map_test( reduce_one,num_1) )
  530. #
  531. #
  532. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  533. # # map_test( square_itself,num_1):
  534. # # [1, 4, 9, 25, 49, 100]
  535. # # map_test( add_one,num_1) :
  536. # # [2, 3, 4, 6, 8, 11]
  537. # # map_test( reduce_one,num_1):
  538. # # [0, 1, 2, 4, 6, 9]
  539. # #
  540. # # Process finished with exit code 0
  541. # # 上面函数的另外一种表达方式
  542. # # 使用匿名函数
  543. # num_1 = [1,2,3,5,7,10]
  544. # def map_test(func,array):
  545. # #func 实现方法程序的地址
  546. # #array 传入列表
  547. # ret = []
  548. # for i in array:
  549. # # 实现某功能的方法
  550. # # ret.append(i**2) # 求平方方法
  551. # res = func(i) # 写成一个步骤就是 ret.append( func(i) )
  552. # ret.append( res ) # 写成一个步骤就是 ret.append( func(i) )
  553. # return ret
  554. #
  555. # print( "map_test( lambda x :x**2,num_1):")
  556. # print( map_test( lambda x :x**2,num_1) )
  557. #
  558. # print( "map_test( lambda x :x+1,num_1) :")
  559. # print( map_test( lambda x :x+1,num_1) )
  560. #
  561. # print( "map_test( lambda x :x-1,num_1):")
  562. # print( map_test( lambda x :x-1,num_1) )
  563. #
  564. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  565. # # map_test( lambda x :x**2,num_1):
  566. # # [1, 4, 9, 25, 49, 100]
  567. # # map_test( lambda x :x+1,num_1) :
  568. # # [2, 3, 4, 6, 8, 11]
  569. # # map_test( lambda x :x-1,num_1):
  570. # # [0, 1, 2, 4, 6, 9]
  571. # #
  572. # # Process finished with exit code 0
  573. # # 15、map
  574. # # map(功能,处理内容)
  575. # # 另外一种表达方式
  576. # # 使用内置函数 map(功能,处理内容)
  577. # num_1 = [1,2,3,5,7,10]
  578. #
  579. # res1 = map(lambda x: x ** 2, num_1) # 存储的是map返回的迭代器的地址
  580. # print( "map(lambda x: x ** 2, num_1):")
  581. # print( list(res1) )
  582. #
  583. # res2 = map( lambda x :x+1,num_1) # 存储的是map返回的迭代器的地址
  584. # print( "map( lambda x :x+1,num_1) :")
  585. # print( list(res2 ) )
  586. #
  587. # res3 = map( lambda x :x-1,num_1) # 存储的是map返回的迭代器的地址
  588. # print( "map( lambda x :x-1,num_1):")
  589. # print( list(res3 ) )
  590. #
  591. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  592. # # map(lambda x: x ** 2, num_1):
  593. # # [1, 4, 9, 25, 49, 100]
  594. # # map( lambda x :x+1,num_1) :
  595. # # [2, 3, 4, 6, 8, 11]
  596. # # map( lambda x :x-1,num_1):
  597. # # [0, 1, 2, 4, 6, 9]
  598. # #
  599. # # Process finished with exit code 0
  600. # # 关于map使用的注意事项:
  601. # # map返回的是一个迭代器,如果使用for进行输出的话,那么for运行结束后,迭代器的内容就全部输出完毕,
  602. # # =====》变为空
  603. # # 如上面的列子
  604. #
  605. # num_1 = [1,2,3,5,7,10]
  606. #
  607. # res1 = map(lambda x: x ** 2, num_1) # 存储的是map返回的迭代器的地址
  608. # for i in res1:
  609. # print(i)
  610. # print( "map(lambda x: x ** 2, num_1):")
  611. # print( list(res1) ) # 迭代器的内容被取完,为空
  612. # #
  613. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  614. # # 1
  615. # # 4
  616. # # 9
  617. # # 25
  618. # # 49
  619. # # 100
  620. # # map(lambda x: x ** 2, num_1):
  621. # # []
  622. # #
  623. # # Process finished with exit code 0
  624. # 09
  625. # 09
  626. # 09
  627. # # 16、filter(功能,内容)
  628. # 过滤掉 movie_people中 开始含有sb 的人
  629. # # 基础形式实现
  630. # movie_people = ["sb_alex","sb_wupeiqi","linhaifeng","sb_yuanhao"]
  631. #
  632. # ret =[]
  633. # for p in movie_people:
  634. # if not p.startswith("sb"):
  635. # ret.append(p)
  636. # print(ret)
  637. #
  638. #
  639. # # 函数功能实现
  640. # movie_people = ["sb_alex","sb_wupeiqi","linhaifeng","sb_yuanhao"]
  641. # def filter_test(array):
  642. # ret =[]
  643. # for p in array:
  644. # if not p.startswith("sb"):
  645. # ret.append(p)
  646. # return ret
  647. #
  648. # res = filter_test(movie_people)
  649. # print( res)
  650. # #
  651. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  652. # # ['linhaifeng']
  653. # #
  654. # # Process finished with exit code 0
  655. # # 函数功能实现
  656. # movie_people = ["sb_alex","sb_wupeiqi","linhaifeng","sb_yuanhao"]
  657. # def filter_test(func,array):
  658. # ret =[]
  659. # for p in array:
  660. # # if not p.startswith("sb"):
  661. # if not func(p):
  662. # ret.append(p)
  663. # return ret
  664. #
  665. # res = filter_test(lambda x: x.startswith("sb"),movie_people)
  666. # print( res)
  667. #
  668. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  669. # # ['linhaifeng']
  670. # #
  671. # # Process finished with exit code 0
  672. # # 17、filter(功能,内容)
  673. # # filter实现
  674. # # filter的第一个参数为真,就保留结果
  675. # movie_people = ["sb_alex","sb_wupeiqi","linhaifeng","sb_yuanhao"]
  676. #
  677. # res = filter(lambda x: x.startswith("sb"),movie_people) # 返回结果的地址
  678. # print( list(res) )
  679. #
  680. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  681. # # ['sb_alex', 'sb_wupeiqi', 'sb_yuanhao']
  682. # #
  683. # # Process finished with exit code 0
  684. # # filter实现
  685. # # filter的第一个参数为真,就保留结果, 因此要过滤掉参数中含有开始为“sb”的内容,应该在lambda中加入not
  686. # #
  687. # movie_people = ["sb_alex","sb_wupeiqi","linhaifeng","sb_yuanhao"]
  688. #
  689. # res = filter(lambda x: not x.startswith("sb"),movie_people) # 返回结果的地址
  690. # print( list(res) )
  691. # #
  692. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  693. # # ['linhaifeng']
  694. # #
  695. # # Process finished with exit code 0
  696. # 10
  697. # 10
  698. # 10
  699. # # 基本功能实现 num_l中的所有的数据相加
  700. # num_1 = [1,2,3,100]
  701. # res =0
  702. # for num in num_1:
  703. # res +=num
  704. #
  705. # print(res)
  706. #
  707. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  708. # # 106
  709. # #
  710. # # Process finished with exit code 0
  711. #
  712. # # # 函数功能实现 num_l中的所有的数据相加
  713. # num_1 = [1,2,3,100]
  714. # def reduce_test(array) :
  715. # res =0
  716. # for num in array:
  717. # res +=num
  718. # return res
  719. # res = reduce_test(num_1)
  720. # print(res)
  721. # # 函数功能实现 num_l中的所有的数据 相加
  722. # num_1 = [1,2,3,100]
  723. # def reduce_test(func, array, init = None) :
  724. # if init is None:
  725. # res = array.pop(0)
  726. # else:
  727. # res = init
  728. #
  729. # for num in array:
  730. # res =func(res,num)
  731. # return res
  732. #
  733. # res = reduce_test( lambda x,y: x+y, num_1)
  734. # print(res)
  735. #
  736. # res = reduce_test( lambda x,y: x*y, num_1,10)
  737. # print(res)
  738. # #
  739. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  740. # # 106
  741. # # 6000
  742. # #
  743. # # Process finished with exit code 0
  744. # # 函数功能实现 num_l中的所有的数据相乘
  745. # num_1 = [1,2,3,100]
  746. # def reduce_test(func, array, init = None) :
  747. # if init is None:
  748. # res = array.pop(0)
  749. # else:
  750. # res = init
  751. #
  752. # for num in array:
  753. # res =func(res,num)
  754. # return res
  755. #
  756. # res = reduce_test( lambda x,y: x*y, num_1)
  757. # print(res)
  758. #
  759. # res = reduce_test( lambda x,y: x*y, num_1,10)
  760. # print(res)
  761. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  762. # # 600
  763. # # 6000
  764. # #
  765. # # Process finished with exit code 0
  766. # # 17、map reduce filter总结
  767. # 11
  768. # 11
  769. # 11、map reduce filter总结
  770. # reduce() 函数会对参数序列中元素进行累积。
  771. # 函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给 reduce 中的函数 function
  772. # (有两个参数)先对集合中的第 1、2 个元素进行操作,得到的结果再与第三个数据用 function 函数运算,
  773. # 最后得到一个结果。
  774. # reduce 函数 实现上述的功能
  775. # from functools import reduce
  776. # num_1 = [1,2,3,100]
  777. # print(reduce( lambda x,y: x*y, num_1,10)) # 10是放大系数
  778. # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  779. # 6000
  780. #
  781. # Process finished with exit code 0
  782. #
  783. # 处理序列中的每个元素,得到的结果是一个‘列表’,该‘列表’元素个数及位置与原来一样
  784. # map()
  785. # filter遍历序列中的每个元素,判断每个元素得到布尔值,如果是True则留下来
  786. # people = [
  787. # {"name": "alex", "age": 10000},
  788. # {"name": "wupeiqi", "age": 1000},
  789. # {"name": "yuanhao", "age": 100},
  790. # {"name": "linhaifeng", "age": 18},
  791. #
  792. # ]
  793. #
  794. # res = (filter( lambda p: p["age"]<= 18,people))
  795. # # print(filter( lambda p: p["age"]<= 18,people))
  796. # print(list(res))
  797. #
  798. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  799. # # [{'name': 'linhaifeng', 'age': 18}]
  800. # #
  801. # # Process finished with exit code 0
  802. # # 18、关于reduce的求和实例
  803. # # reduce: 处理一个序列,然后把序列进行合并
  804. #
  805. # from functools import reduce
  806. # print(reduce(lambda x,y: x+y,range(5),100)) # 100为初始值,实现对闭区间范围【0,4】的所有整数求和: 100+0+1+2+3+4
  807. # print(reduce(lambda x,y: x+"->"+y,"abcdef"))
  808. #
  809. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  810. # # 110
  811. # # a->b->c->d->e->f
  812. # #
  813. # # Process finished with exit code 0
  814. # 12
  815. # 12
  816. # 12
  817. # 12、1 abs
  818. # # 19、abs() 函数返回数字的绝对值。
  819. # print(abs(-1))
  820. # print(abs(1))
  821. #
  822. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  823. # # 1
  824. # # 1
  825. # #
  826. # # Process finished with exit code 0
  827. # # 20、all
  828. # all() 函数用于判断给定的可迭代参数 iterable 中的所有元素是否 都为 TRUE ,如果是返回 True,否则返回 False。
  829. # 元素除了是 0、空、FALSE 外都算 TRUE。
  830. # print(all([1,2,"11"]))
  831. # print(all([1,2,"11",""]))
  832. # print(all([1,2,"11",()]))
  833. #
  834. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  835. # # True
  836. # # False
  837. # # False
  838. # #
  839. # # Process finished with exit code 0
  840. #
  841. # # 21、 any()
  842. # # any() 函数用于判断给定的可迭代参数 iterable 是否 全部为 Fals e,则返回 False,如果有一个为 True,则返回 True。
  843. # # 元素除了是 0、空、FALSE ,None 外都算 TRUE。
  844. # print(any([1,2,"11"]))
  845. # print(any([1,2,"11",""]))
  846. # print(any([1,2,"11",()]))
  847. # print(any([0,"",False,None]))
  848. # # 22、bin
  849. # bin() 返回一个整数 int 或者长整数 long int 的二进制表示。
  850. # print(bin(5))
  851. #
  852. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  853. # # 0b101
  854. # #
  855. # # Process finished with exit code 0
  856. # # 23、bool
  857. # # bool() 函数用于将给定参数转换为布尔类型,如果没有参数,返回 False。
  858. # print("1: ",bool(1) )
  859. # print("111: ",bool("111") )
  860. # print("[1,2] ",bool([1,2]) )
  861. # print("["111","aaa"] ",bool(["111","aaa"]) )
  862. # print("{"111" :,"aaa"} ",bool({"111" :,"aaa"}) )
  863. #
  864. # print("[] : ",bool([]) )
  865. # print("None ",bool(None) )
  866. # print("{} q`",bool({}) )
  867. # # 24、bytes
  868. # # 25、encoding decode 编码与解码
  869. # 描述
  870. # bytes 函数返回一个新的 bytes 对象,该对象是一个 0 <= x < 256 区间内的整数不可变序列。它是 bytearray 的不可变版本。
  871. #
  872. # 语法
  873. # 以下是 bytes 的语法:
  874. # class bytes([source[, encoding[, errors]]])
  875. # 参数
  876. # 如果 source 为整数,则返回一个长度为 source 的初始化数组;
  877. # 如果 source 为字符串,则按照指定的 encoding 将字符串转换为字节序列;
  878. # 如果 source 为可迭代类型,则元素必须为[0 ,255] 中的整数;
  879. # 如果 source 为与 buffer 接口一致的对象,则此对象也可以被用于初始化 bytearray。
  880. # 如果没有输入任何参数,默认就是初始化数组为0个元素。
  881. #
  882. #
  883. # name = "你好"
  884. # print(bytes( name,encoding="utf-8")) # 输出的是16进制,1个汉字用3个字节比较
  885. # print(bytes( name,encoding="utf-8").decode("utf-8"))
  886. # print(bytes( name,encoding="utf-8").decode()) # 不写的话,python3中默认utf-8
  887. #
  888. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  889. # # b'\xe4\xbd\xa0\xe5\xa5\xbd'
  890. # # 你好
  891. # # 你好
  892. # #
  893. # # Process finished with exit code 0
  894. # name = "你好"
  895. # print(bytes( name,encoding="gbk")) # 输出的是16进制,1个汉字用2个字节比较
  896. # print(bytes( name,encoding="gbk").decode("gbk"))
  897. # print(bytes( name,encoding="gbk").decode()) # 默认是utf-8 解码,结果出现解码错误
  898. #
  899. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  900. # # b'\xc4\xe3\xba\xc3'
  901. # # 你好
  902. # # Traceback (most recent call last):
  903. # # File "D:/C_cache/py/python_practice/day16_NiMingHanShu.py", line 864, in <module>
  904. # # print(bytes( name,encoding="gbk").decode())
  905. # # UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
  906. # #
  907. # # Process finished with exit code 1
  908. # # 26、chr
  909. # chr() 用一个范围在 range(256)内的(就是0~255)整数作参数,返回一个对应的字符。
  910. # print(chr(100) )
  911. # print(chr(45) )
  912. #
  913. #
  914. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  915. # # d
  916. # # -
  917. # #
  918. # # Process finished with exit code 0
  919. # # 27、dir()
  920. # dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。
  921. # 如果参数包含方法__dir__(),该方法将被调用。如果参数不包含__dir__(),该方法将最大限度地收集参数信息。
  922. #
  923. # print(dir(dict))
  924. #
  925. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  926. # # ['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
  927. # #
  928. # # Process finished with exit code 0
  929. # # 28、divmod
  930. # python divmod() 函数把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b)。
  931. # 在 python 2.3 版本之前不允许处理复数。
  932. #
  933. # 函数语法
  934. # divmod(a, b)
  935. #
  936. # 参数说明:
  937. # a: 数字
  938. # b: 数字
  939. # 关于应用实例说明,求出的 整数+余数 能够应用于搜索页面的显示。如百度搜索“信息a”,10条,一页3条
  940. # 那么,divmod(10 , 3)==> (3, 1) ,就是说,显示需要3页+1条, 那么结果应该,显示4页
  941. # print(divmod(10 , 3))
  942. #
  943. #
  944. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  945. # # (3, 1)
  946. # #
  947. # # Process finished with exit code 0
  948. # # 29、str与字典
  949. # dic = {"name": "alex"}
  950. # dic_str = str(dic)
  951. # dic_str1 = "{'name': 'alex'}" # dic_str1 = "{"name": "alex"}" 这样子会报错
  952. # print("dic: ",dic ,type(dic))
  953. # print("dic_str:",dic_str,type(dic_str))
  954. # print("dic_str1:",dic_str1,type(dic_str1))
  955. #
  956. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  957. # # dic: {'name': 'alex'} <class 'dict'>
  958. # # dic_str: {'name': 'alex'} <class 'str'>
  959. # # dic_str1: {'name': 'alex'} <class 'str'>
  960. # #
  961. # # Process finished with exit code 0
  962. # # 30、eval()
  963. # =====> 下列的应用,实际上就是去掉字符串两边的 “ "" ”符号,返回里头的表达式
  964. # =====> 也就是把字符串中的数据结构给提取出来
  965. # 描述
  966. # eval() 函数用来执行一个字符串表达式,并返回表达式的值。
  967. #
  968. # 语法
  969. # 以下是 eval() 方法的语法:
  970. #
  971. # eval(expression[, globals[, locals]])
  972. # 参数
  973. # expression -- 表达式。
  974. # globals -- 变量作用域,全局命名空间,如果被提供,则必须是一个字典对象。
  975. # locals -- 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。
  976. # 返回值
  977. # 返回表达式计算结果。
  978. #
  979. # dic = {"name": "alex"}
  980. # dic_str = str(dic)
  981. # dic_str1 = "{'name': 'alex'}" # dic_str1 = "{"name": "alex"}" 这样子会报错
  982. # print("dic: ",dic ,type(dic))
  983. # print("dic_str:",dic_str,type(dic_str))
  984. # print("dic_str1:",dic_str1,type(dic_str1))
  985. #
  986. # d = eval(dic_str)
  987. # d1 = eval(dic_str1)
  988. # print(d,type(d))
  989. # print(d1,type(d1))
  990. #
  991. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  992. # # dic: {'name': 'alex'} <class 'dict'>
  993. # # dic_str: {'name': 'alex'} <class 'str'>
  994. # # dic_str1: {'name': 'alex'} <class 'str'>
  995. # # {'name': 'alex'} <class 'dict'>
  996. # # {'name': 'alex'} <class 'dict'>
  997. # #
  998. # # Process finished with exit code 0
  999. # eval()的应用
  1000. # 例如计算一个等式,输入的是一个字符串,我们需要将里头的结果计算出来
  1001. # express = "1+2*(3/3-1)-2"
  1002. # print(express)
  1003. # print(eval(express) )
  1004. #
  1005. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1006. # # 1+2*(3/3-1)-2
  1007. # # -1.0
  1008. # #
  1009. # # Process finished with exit code 0
  1010. # # 31、hash
  1011. # 可hash的数据类型即不可变数据类型,
  1012. # 不可hash的数据类型即 可变数据类型
  1013. # print(hash("132134649745467897975safsafsafasdfsfdsdfasadf"))
  1014. # print(hash("1"))
  1015. # print(hash("a"))
  1016. #
  1017. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1018. # # -7424390623122969874
  1019. # # -22698245628170108
  1020. # # -4943392740421642797
  1021. # #
  1022. # # Process finished with exit code 0
  1023. # # hash 前后的计算编码值保持不变
  1024. # name = "alex"
  1025. # print(hash(name))
  1026. # print(hash(name))
  1027. #
  1028. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1029. # # 8721249888825822418
  1030. # # 8721249888825822418
  1031. # #
  1032. # # Process finished with exit code 0
  1033. # # hash 编码的内容一旦修改,hash的计算的结果就会改变
  1034. # name = "alex"
  1035. # print("====>before",hash(name))
  1036. # name = "--_--"
  1037. # print("====>after ",hash(name))
  1038. #
  1039. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1040. # # ====>before 7905044469795841811
  1041. # # ====>after -4425303464219513957
  1042. # #
  1043. # # Process finished with exit code 0
  1044. # # 32、help()
  1045. # # 打印帮助
  1046. # print(help(all))
  1047. #
  1048. # # D:\Anaconda3\python.exe D: / C_cache / py / python_practice / day16_NiMingHanShu.py
  1049. # # Help on built - in function
  1050. # # all in module
  1051. # # builtins:
  1052. # # all(iterable, /)
  1053. # # Return True if bool(x) is True for all values x in the iterable.
  1054. # #
  1055. # # If the iterable is empty,return True.
  1056. # # None
  1057. # # Process finished with exit code 0
  1058. # # 33、bin oct hex
  1059. # # bin 十进制===》 二进制
  1060. # # oct 十进制===》 8进制
  1061. # # hex 十进制 ==>十六进制
  1062. # print(bin(17))
  1063. # print(oct(17))
  1064. # print(hex(17))
  1065. #
  1066. #
  1067. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1068. # # 0b10001
  1069. # # 0o21
  1070. # # 0x11
  1071. # #
  1072. # # Process finished with exit code 0
  1073. # # 34、isinstance()
  1074. # # 描述
  1075. # # isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
  1076. # # isinstance() 与 type() 区别:
  1077. # # type() 不会认为子类是一种父类类型,不考虑继承关系。
  1078. # # isinstance() 会认为子类是一种父类类型,考虑继承关系。
  1079. # #
  1080. # # 如果要判断两个类型是否相同推荐使用 isinstance()。
  1081. #
  1082. # a = 111
  1083. # print("(a,int) ",isinstance(a,int))
  1084. # print("(a,str) ",isinstance(a,str))
  1085. # print("(a,list) ",isinstance(a,list))
  1086. # print("(a,tuple) ",isinstance(a,tuple))
  1087. # print("(a,set) ",isinstance(a,set))
  1088. # print("(a,dict) ",isinstance(a,dict))
  1089. #
  1090. # print("(\"111\",int)) ",isinstance("111",int))
  1091. # print("(a,(str,int,tuple) ",isinstance(a,(str,int,tuple))) # a是括号中,即元组内容的子类
  1092. #
  1093. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1094. # # (a,int) True
  1095. # # (a,str) False
  1096. # # (a,list) False
  1097. # # (a,tuple) False
  1098. # # (a,set) False
  1099. # # (a,dict) False
  1100. # # ("111",int)) False
  1101. # # (a,(str,int,tuple) True
  1102. # #
  1103. # # Process finished with exit code 0
  1104. # # 35、globals
  1105. # globals() 函数会以字典类型返回当前位置的全部全局变量。
  1106. # 参数
  1107. # 无
  1108. # 返回值
  1109. # 返回全局变量的字典。
  1110. # name = "===================>2333二哈哈哈哈哈哈哈哈"
  1111. # print(globals()) # 打印出来的最右边有name的信息,因为其是全局变量
  1112. # print( __file__ ) # 两个下划线
  1113. #
  1114. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1115. # # {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000000000059D0F0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:/C_cache/py/python_practice/day16_NiMingHanShu.py', '__cached__': None, 'name': '===================>2333二哈哈哈哈哈哈哈哈'}
  1116. # # D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1117. # #
  1118. # # Process finished with exit code 0
  1119. # # 36、locals
  1120. # 描述
  1121. # locals() 函数会以字典类型返回当前位置的全部局部变量。
  1122. # 对于函数, 方法, lambda 函式, 类, 以及实现了 __call__ 方法的类实例, 它都返回 True。
  1123. #
  1124. # name = "????"
  1125. # def P():
  1126. # name = "===================>2333二哈哈哈哈哈哈哈哈"
  1127. # print(name)
  1128. # print("locals:==>",locals()) # 打印出来的最右边有name的信息,因为其是全局变量
  1129. #
  1130. #
  1131. # P()
  1132. # print("name: ",name)
  1133. #
  1134. # print("globals==>",globals()) # 打印出来的最右边有name的信息,因为其是全局变量
  1135. # print("locals:==>",locals()) # 打印出来的最右边有name的信息,因为其是全局变量
  1136. #
  1137. #
  1138. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1139. # # ===================>2333二哈哈哈哈哈哈哈哈
  1140. # # locals:==> {'name': '===================>2333二哈哈哈哈哈哈哈哈'}
  1141. # # name: ????
  1142. # # globals==> {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000000000214D0F0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:/C_cache/py/python_practice/day16_NiMingHanShu.py', '__cached__': None, 'name': '????', 'P': <function P at 0x00000000020A1EA0>}
  1143. # # locals:==> {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x000000000214D0F0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'D:/C_cache/py/python_practice/day16_NiMingHanShu.py', '__cached__': None, 'name': '????', 'P': <function P at 0x00000000020A1EA0>}
  1144. # #
  1145. # # Process finished with exit code 0
  1146. # # 37、min max
  1147. # min 求最小值
  1148. # max 求最大值
  1149. # l = [1,3,100,-1,2]
  1150. # print(max(l))
  1151. # print(min(l))
  1152. #
  1153. #
  1154. # # D:\Anaconda3\python.exe D:/C_cache/py/python_practice/day16_NiMingHanShu.py
  1155. # # 100
  1156. # # -1
  1157. # #
  1158. # # Process finished with exit code 0

day16_函数作用域_匿名函数_函数式编程_map_reduce_filter_(部分)内置函数的更多相关文章

  1. Python笔记_第四篇_高阶编程_再议装饰器和再议内置函数

    1. 概述: 我们在前面用了很多的装饰器这个工具的方法.这个位置要系统的讲一下装饰器. 1.2 为什么需要装饰器. 装饰器本质是一个Python函数,它可以让其他函数在不需要任何代码变动的前提下增加额 ...

  2. 【mysql的编程专题③】内置函数

    数学函数 常用 abs(x) 返回x的绝对值 floor(x) 返回小于x的最大整数值 mod(x,y) 返回x/y的模(余数) rand() 返回0到1内的随机值,可以通过提供一个参数(种子)使ra ...

  3. scoping作用域,anonymous function匿名函数,built-in functions内置函数

    作用域练习1 def test1(): print('in the test1') def test(): print('in the test') return test1 res = test() ...

  4. Python-老男孩-01_基础_文件IO_函数_yield_三元_常用内置函数_反射_random_md5_序列化_正则表达式_time

    Python2.7 缩进统一: 约定  常量 大写 , 变量  小写 判断一个变量在内存中的地址,也能看出是不是一个值 id()函数 >>> x = 'abc' >>&g ...

  5. 简学Python第三章__函数式编程、递归、内置函数

    #cnblogs_post_body h2 { background: linear-gradient(to bottom, #18c0ff 0%,#0c7eff 100%); color: #fff ...

  6. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

  7. day14(1)--递归、匿名函数、内置函数

    一.递归 定义:本质上是回溯和递推 回溯:询问答案的过程 递推:推出答案的过程 前提: 回溯到一个有结果的值开始递推 回溯与递推的条件要有规律 方式: 直接递归:自己调用自己 间接递归:通过别人来调用 ...

  8. python递归-三元表达式-列表生成式-字典生成式-匿名函数-部分内置函数-04

    递归 递归: # 函数在调用阶段直接或间接地又调用了自身 应用场景: # 将列表中的数字依次打印出来(循环的层数是你必须要考虑的点)   -->  l = [1, [2, [3, [4, [5, ...

  9. Python经常使用内置函数介绍【filter,map,reduce,apply,zip】

    Python是一门非常简洁,非常优雅的语言,其非常多内置函数结合起来使用,能够使用非常少的代码来实现非常多复杂的功能,假设相同的功能要让C/C++/Java来实现的话,可能会头大,事实上Python是 ...

  10. python部落刷题宝学到的内置函数

    最近加入了python部落,感觉里面的刷题宝很有意思,玩了一下,知道了许多以前并不清楚的内置函数,然后感觉到快要记不住了,所以开始陈列一下 1.divmod(a,b):取a除以b的商和余数,功效等价于 ...

随机推荐

  1. javascript 跨域问题 jsonp

    转载:http://www.cnblogs.com/choon/p/5393682.html demo 用动态创建<script></script>节点的方式实现了跨域HTTP ...

  2. Spring boot热部署实战

    1.介绍 在开发工程中,修改一点儿代码,想看效果就需要重新启动服务,这样会花费大量时间在重启服务上,通过devtools热部署可以大大减少重启服务的时间. 之所以能减少时间,是因为Spring Boo ...

  3. 全球首个开放应用模型 OAM 开源

    业界要闻 全球首个开放应用模型 OAM 开源 2019 年 10 月 17 日,阿里巴巴合伙人.阿里云智能基础产品事业部总经理蒋江伟(花名:小邪)在 Qcon 上海重磅宣布,阿里云与微软联合推出开放应 ...

  4. Python 列表,元组,字典

    0)字符串切片 py_str = 'python' >>>py_str[0] #取第一个字符串,返回值为"p",超出范围会报错 >>>py_st ...

  5. NOIp2018集训test-9-5(am)

    Problem A. maze 递归处理,题解写得真简单. 我大概这辈子也写不出来这种东西吧. Problem B. count 容易发现合法的数中一定有且仅有两个数加起来等于10,其他数两两配对加起 ...

  6. NX二次开发-UFUN删除工程图UF_DRAW_delete_drawing

    NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize ...

  7. win7+vs2010配置驱动开发环境(问题种种版...)

     本来按照这个来做,能跑通helloworld,可是复杂的驱动就会出错....不知道什么原因,后来就直接用命令行来编译的. -------------------------------------- ...

  8. 关于double的输入输出

    double定义的变量输入的时候一定要%lf输入,要是%f输入的话,得到的结果会是0 float输入的时候是%f 但是在输出的时候%lf和%f都可以输出 建议使用double类型时,用%lf输入,%f ...

  9. 《DSP using MATLAB》Problem 9.2

    前几天看了看博客,从16年底到现在,3年了,终于看书到第9章了.都怪自己愚钝不堪,唯有吃苦努力,一点一点一页一页慢慢啃了. 代码: %% ------------------------------- ...

  10. hadoop 8088 看不到mapreduce 任务的执行状态

    进到8088页面后,怎么看不到mapreudce的执行状态,有哪里需要配置的 解决办法: 在$HADOOP_HOME/conf/mapred-site.xml 在原来的配置文件基础之上添加: < ...