码迷,mamicode.com
首页 > 编程语言 > 详细

python之路---22 初始模块 random time collections functools

时间:2019-01-02 23:20:10      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:分享图片   too   import   代码块   --   png   order   时间戳   alt   

一 .初始模块

  1.从?到?的顺序: ?条代码 < 语句块 < 代码块(函数, 类) < 模块

  2.引入模块的方式

    ①   import   模块

    ②   from   模块  import    功能

技术分享图片

 

 二.     random模块

技术分享图片

三 time 模块

  1.时间戳                 从1970-01-01  00:00:00  开始以 秒  计算

                    东八区  从1970-01-01  08:00:00

      time.time()        用于时间存储   

技术分享图片

 

     2.格式化

技术分享图片

 

技术分享图片

技术分享图片

 

  3.结构化(python的时间)

技术分享图片

 

   4 转化

技术分享图片

技术分享图片

四.    collections  模块

  1.counter (可迭代对象)         计数

    每一个元素出现的次数

     获取到的结果可以像字典?样进?使?

  2.defaultdict( lambda:0)   默认值字典

  3.OrderedDict( )    将字典有序化

  4.数据结构( 栈   队列)

    ①栈:  先进后出

技术分享图片

技术分享图片

 

      ②队列: 先进先出

技术分享图片

    ③双向

技术分享图片

   5.namedtuple    命名元组

    类似创建一个类

面向对象:

技术分享图片

命名元组:

技术分享图片

 

 五.functools  模块

  1.wraps    (装饰器中)  可以改变一个函数的名字 ,注释

技术分享图片

 

   2.reduce    归纳   

技术分享图片

 

  3.partial    偏函数  固定函数中的参数

      新函数 = (旧参数,固定值)

技术分享图片

python之路---22 初始模块 random time collections functools

标签:分享图片   too   import   代码块   --   png   order   时间戳   alt   

原文地址:https://www.cnblogs.com/amirky/p/10211595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!