上一页 1 ··· 44 45 46 47 48
摘要: from collections import Iterable print(isinstance({},iterable)) # 判断是否可迭代 from collections import Iterator #判断是否是迭代器 instance((x for x in range(5)),It 阅读全文
posted @ 2018-05-16 21:31 python我的最爱 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 1. 生成器 只有在调用时才会生成相应的数据 2 . 只记录当前的位置3 . 只有一个__next__() f = (x for x in range(10)) #一个简单的生成器 print(f.__next__()) 费波纳生成器(举例1) def fib(max): n,a,b = 0, 0, 阅读全文
posted @ 2018-05-16 20:47 python我的最爱 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 高阶函数 + 嵌套函数 =》装饰器 import timedef timer(func): def wrapper(*args, **kwargs): start_time = time.time() func(*args, **kwargs) end_time = time.time() prin 阅读全文
posted @ 2018-05-16 17:56 python我的最爱 阅读(122) 评论(0) 推荐(0) 编辑
摘要: 1.school = 'oldboy.edu' def change_name(name): school = " Mage Linux" # 局部变量只在函数里生效 print(name, school) name = 'Alex' change_name(name) #先调用 print(sch 阅读全文
posted @ 2018-05-14 16:50 python我的最爱 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1.def test(x, y): print(x, y) test(y=1, x=2) test(2 , y=1) #位置参数一定要在关键字参数的前面 def test(x, y, z): print(x, y, z) test(2, z=1, y=2) 2.默认参数 def test(x, y= 阅读全文
posted @ 2018-05-14 16:37 python我的最爱 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 1. 集合的去重作用 list_1 = [1, 4, 5, 7, 3, 6, 7, 9] list_1 = set(list_1) list2 = set([2, 6, 0, 66, 22, 8, 4]) 2.#交集 intersection list_1.intersection(list_2) 阅读全文
posted @ 2018-05-14 16:06 python我的最爱 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 文件打开: 1. f = open('yesterday,‘r+’,encoding = ‘utf-8’) 读取的方式加载为Utf-8 r 打开文件并写, 只适用于文字类 r+ 打开文件并读写,文件的指针定位在文件的开始位置;文件不存在就报错 w 打开文件只读操作, 如果文件存在就清空文件,文件不存 阅读全文
posted @ 2018-05-14 14:28 python我的最爱 阅读(212) 评论(0) 推荐(0) 编辑
摘要: info = { ’stu1101‘ : ’xiaoming’, ‘stu1102 : xiahong‘, ’stu1103 : ‘xiaozhi', } 1. 字典的获取 info.get('stu1104',None) # 有就获取,没有就返回None 2. 字典的跟新 b = {'stu110 阅读全文
posted @ 2018-05-11 11:26 python我的最爱 阅读(312) 评论(0) 推荐(0) 编辑
摘要: name = "my \tname is alex" #\t 空格 1. name.capitalize() #首字母大写 2.name.count('a') # 对字母a计数 3.name.center(50,'-') # 把name 写在中心,不够补齐 4.name.encode('uft-8' 阅读全文
posted @ 2018-05-10 22:29 python我的最爱 阅读(226) 评论(0) 推荐(0) 编辑
摘要: 举例说明:names = ["zhangyang", "guyun", 'xiangpeng', ['alex','jack'], "xuliangcheng"] print(type(names)) 1. list 切片: extract_name = names[0:3] # 切片 顾头不顾尾 阅读全文
posted @ 2018-05-10 21:19 python我的最爱 阅读(271) 评论(0) 推荐(0) 编辑
上一页 1 ··· 44 45 46 47 48