python模块 - day8

1、用模块原因

为了节省内存

2、什么是模块

  • python代码或者C语言代码
  •  以功能来分类

3、模块分类

  • 内置模块,包含在python解释器内的模块
  • 扩展模块,需要安装
import time
for i in range(0,101,2):
     time.sleep(0.1)
     char_num = i//2      #打印多少个'*'
     per_str = '\r%s%% : %s\n' % (i, '*' * char_num) if i == 100 else '\r%s%% : %s'%(i,'*'*char_num)
     print(per_str,end='', flush=True)
打印进度条

 4、内置模块

  • collections  :   扩展数据库型
import collections
t = collections.namedtuple('tuples',['a','b','c'])
mytup = t(24,'wang',80)
print(mytup)
View Code
结果:
tuples(a=24, b='wang', c=80)
先指定key,相当于定义一个类;
再指定value,相当于实例化这个类;
  • deque是为了高效实现插入和删除操作的双向列表,适合用于队列和栈
    from collections import deque
    q = deque(['a', 'b', 'c'])
     q.append('x')
     q.appendleft('y')
     q
    deque(['y', 'a', 'b', 'c', 'x'])
    View Code

     

posted @ 2018-06-30 10:25  MyHans  阅读(89)  评论(0)    收藏  举报