摘要:
import time as tfrom os import pathdef createFile(dest): date = t.localtime(t.time()) name = '%d_%d_%d.txt' %(date[1],date... 阅读全文
posted @ 2017-06-11 20:38
2021年的顺遂平安君
阅读(65)
评论(0)
推荐(0)
摘要:
查看当前目录下所要创建的 文件是否已经存在,如果不存在就创建,并写入30个换行( ) 要点: 所要读写的文件名可以是_变量_ 阅读全文
posted @ 2017-06-11 20:38
2021年的顺遂平安君
阅读(159)
评论(0)
推荐(0)
摘要:
基本用法: Dictionary 使用 不能返回一个list,需要使用 或`sorted(D)`,会返回 Dictionary 的 keys,并存入 list。 阅读全文
posted @ 2017-06-11 17:19
2021年的顺遂平安君
阅读(415)
评论(0)
推荐(0)
摘要:
基本用法: .keys.values.items >>> D = dict(a=1,b=2,c=3)>>> D{'a': 1, 'b': 2, 'c': 3}>>> D.keys>>> D.keys()dict_keys(['a', 'b', 'c']... 阅读全文
posted @ 2017-06-11 17:19
2021年的顺遂平安君
阅读(65)
评论(0)
推荐(0)
摘要:
range 不是 iterator >>> R = range(3)>>> next(R)Traceback (most recent call last): File "", line 1, in TypeError: 'range' object ... 阅读全文
posted @ 2017-06-11 17:08
2021年的顺遂平安君
阅读(93)
评论(0)
推荐(0)
摘要:
1. _range_ 不是 iterator 2. _range_ 允许 multiple iterators,并且能记住每个iterator的位置。 ,`map filter`都不允许 multiple iterators。它们的 iter 就是它们本身,因为不需要专门使用 iter 函数。 阅读全文
posted @ 2017-06-11 17:08
2021年的顺遂平安君
阅读(942)
评论(0)
推荐(0)
摘要:
要注意 _zip_ 也是_one pass iterator !被遍历一次之后会自动_消失_。 zip类型支持list,next等: 阅读全文
posted @ 2017-06-11 17:00
2021年的顺遂平安君
阅读(176)
评论(0)
推荐(0)
摘要:
>>> z = zip((2,3,4),(33,44,55))>>> z>>> list(z)[(2, 33), (3, 44), (4, 55)] 要注意 ** zip 也是_one-pass iterator** !被遍历一次之后会自动_消失_。 ... 阅读全文
posted @ 2017-06-11 17:00
2021年的顺遂平安君
阅读(59)
评论(0)
推荐(0)
摘要:
Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to ... 阅读全文
posted @ 2017-06-11 16:25
2021年的顺遂平安君
阅读(65)
评论(0)
推荐(0)
摘要:
Ctrl + a – go to the start of the command line Ctrl + e – go to the end of the command line Ctrl + k – delete from cursor to the end of the command li 阅读全文
posted @ 2017-06-11 16:25
2021年的顺遂平安君
阅读(234)
评论(0)
推荐(0)
摘要:
Map map(function_to_apply, list_of_inputs) 设有以下代码: 这段代码实现的功能用map函数可以两行完成: 高级一点地,可以用一列函数作为输入: Filter _Filter_ creates a list of elements for which a fu 阅读全文
posted @ 2017-06-11 16:06
2021年的顺遂平安君
阅读(202)
评论(0)
推荐(0)
摘要:
Map map(function_to_apply, list_of_inputs) 设有以下代码: >>> items = [1, 2, 3, 4, 5]>>> squared = []>>> for i in items:... s... 阅读全文
posted @ 2017-06-11 16:06
2021年的顺遂平安君
阅读(52)
评论(0)
推荐(0)
摘要:
在list comprehension中加入if条件判断: 这段代码相当于: 在list comprehension中加入嵌套循环: 这段代码相当于: 阅读全文
posted @ 2017-06-11 15:56
2021年的顺遂平安君
阅读(491)
评论(0)
推荐(0)
摘要:
在list comprehension中加入if条件判断: >>> lines = [line.rstrip() for line in open('script2.py') if line[0] == 'p']>>> lines['print(sys.... 阅读全文
posted @ 2017-06-11 15:56
2021年的顺遂平安君
阅读(60)
评论(0)
推荐(0)
摘要:
>>> L = [1,2,3,4,5]>>> L = [x+10 for x in L]>>> L[11, 12, 13, 14, 15] list comprehension使代码变得简洁。下面这种常用的方法则显得过时: >>> L = [1,2,3... 阅读全文
posted @ 2017-06-11 15:39
2021年的顺遂平安君
阅读(40)
评论(0)
推荐(0)
摘要:
list comprehension使代码变得简洁。下面这种常用的方法则显得过时: 事实上在使用list comprehension时,代码内部相当于执行下面操作: 在可以的使用的地方尽可能使用list comprehension,是一种地道的Python写法。另外,相比 循环, list comp 阅读全文
posted @ 2017-06-11 15:39
2021年的顺遂平安君
阅读(334)
评论(0)
推荐(0)
摘要:
和`I__next__()`效果相同。 阅读全文
posted @ 2017-06-11 15:32
2021年的顺遂平安君
阅读(186)
评论(0)
推荐(0)
摘要:
>>> E=enumerate('spam')>>> E>>> I=iter(E)>>> next(I)(0, 's')>>> next(I)(1, 'p')>>> list(enumerate('spam'))[(0, 's'), (1, 'p'), (... 阅读全文
posted @ 2017-06-11 15:32
2021年的顺遂平安君
阅读(66)
评论(0)
推荐(0)
摘要:
>>> f=open('script2.py')>>> f>>> iter(f) f和iter(f)类型相同,因为file object是它自身的iterator。 ` f.next() 'import sys\n' ` ... 阅读全文
posted @ 2017-06-11 15:25
2021年的顺遂平安君
阅读(58)
评论(0)
推荐(0)
摘要:
和`iter(f)`类型相同,因为file object是它自身的iterator。 ` f.__next__() 'import sys\n' ` list则不是它自身的iterator,所以不能直接使用 ,必须使用一次 函数: 阅读全文
posted @ 2017-06-11 15:25
2021年的顺遂平安君
阅读(134)
评论(0)
推荐(0)
浙公网安备 33010602011771号