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

python 内置函数

时间:2017-09-07 17:02:33      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:class   obj   new   进度   表示   orm   购物   内置函数   log   

一  print( )

  flush的应用——模拟进度条

import time
for i in range(1,101):
    time.sleep(0.1)
    print(\r{}%:{}.format(i,**i),end=‘‘,flush=True)           #\r (return) 表示回车  \n (new line)表示换行,实际上是回车换行
print()
print(END!)

二 hash( )

  1 参数必须是不可变类型。

print(hash(aaa))
print(hash(baaa))
print(hash(123))
print(hash(b123))
print(hash(123))
print(hash(True))
print(hash(False))

  输入:

-4644624363813443981
-4644624363813443981
7614025369805395482
7614025369805395482
123
1
0

 三  map( ) 映射  自带遍历可迭代对象功能

 四  filter( ) 过滤  自带遍历可迭代对象功能

 五  enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,一般用在 for 循环当中。

  用处:购物车

goods={computer:1000,umbrella:200}

e=enumerate(goods,1)
print(e)
for num,name in e:
    print(num,name,goods[name])

  输出:  

<enumerate object at 0x000001C6FDCA85E8>
1 computer 1000
2 umbrella 200

 

  

python 内置函数

标签:class   obj   new   进度   表示   orm   购物   内置函数   log   

原文地址:http://www.cnblogs.com/654321cc/p/7490296.html

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