
python
住在甜点老铺里的猫
这个作者很懒,什么都没留下…
展开
-
python zip()
zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tuple列表。ex1x = [1, 2, 3] y = [4, 5, 6] z = [7, 8, 9] xyz = zip(x, y, z) print xyz[(1, 4, 7), (2, 5, 8), (3, 6, 9)]ex2x = [1, 2, 3] y = [4, 5, 6, 7] xy = zip(x, y) print转载 2018-01-18 16:51:05 · 199 阅读 · 0 评论 -
python range & xrange
range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列xrange 用法与 range 完全相同,所不同的是生成的不是一个list对象,而是一个生成器。>>> range(5) [0, 1, 2, 3, 4] >>> range(1,5) [1, 2, 3, 4] >>> range(0,6,2) [0, 2, 4]转载 2018-01-19 10:39:17 · 232 阅读 · 0 评论 -
python reduce()
Python reduce() 函数 Python 内置函数描述reduce() 函数会对参数序列中元素进行累积。函数将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给reduce中的函数 function(有两个参数)先对集合中的第 1、2 个元素进行操作,得到的结果再与第三个数据用 function 函数运算,最后得到一个结果。语法reduce() 函数语法:reduce(func转载 2018-01-19 12:20:54 · 213 阅读 · 0 评论 -
python time strftime()
Python time strftime()方法描述Python time strftime() 函数接收以时间元组,并返回以可读字符串表示的当地时间,格式由参数format决定。语法strftime()方法语法:time.strftime(format[, t])参数format -- 格式字符串。t -- 可选的参数t是一个struct_time对象。返回值返回以可读字符串表示的当地时间。说明转载 2018-01-19 11:56:09 · 514 阅读 · 0 评论 -
python time asctime()
Python time asctime()方法描述Python time asctime() 函数接受时间元组并返回一个可读的形式为"Tue Dec 11 18:07:14 2008"(2008年12月11日 周二18时07分14秒)的24个字符的字符串。语法asctime()方法语法:time.asctime([t]))参数t -- 9个元素的元组或者通过函数 gmtime() 或 localt转载 2018-01-19 11:57:50 · 1163 阅读 · 0 评论 -
python time localtime()
Python time localtime()方法描述Python time localtime() 函数类似gmtime(),作用是格式化时间戳为本地的时间。如果sec参数未输入,则以当前时间为转换标准。 DST (Daylight Savings Time) flag (-1, 0 or 1) 是否是夏令时。语法localtime()方法语法:time.localtime([ sec ]转载 2018-01-19 12:00:17 · 17123 阅读 · 0 评论 -
python if __name__ == '__main__':
打开一个.py文件时,经常会在代码的最下面看到if __name__ == '__main__':,现在就来介绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__。一个模块的 __name__ 的值取决于如何应用模块。如果 import 一个模块,那么模块__name__ 的值通常为模块文件名,不带路径或者文件扩展名。如果像一个标准的程序样直接运行模块,在这种情况下,转载 2018-01-18 16:59:48 · 163 阅读 · 0 评论