发布于2019-08-07 15:02 阅读(577) 评论(0) 点赞(4) 收藏(1)
1.abs() 绝对值
2.all() 判断列表里的所有值的布尔值(如果迭代列表里的每个值后都是True 则返回True)
print(all([1,2,'1']))
运行结果:
True
Process finished with exit code 0
3.any() 与all相反 ,如果有一个为真 都为真
4.bin() 十进制转换为二进制
5.bool() 判断布尔值 。为False的布尔值(空,None,0)
6.bytes() 将字符串转换成字节
name = '小明' print(bytes(name,encoding='utf-8'))
运行结果:
b'\xe5\xb0\x8f\xe6\x98\x8e' # 6个字节 Process finished with exit code 0
7.decode 解码 (ASCII 不能编码中文)
name = '小明' print(bytes(name,encoding='utf-8').decode('utf-8')) print(bytes(name,encoding='gbk').decode('gbk'))
运行结果:
小明
小明
Process finished with exit code 0
8.chr() 按照ASCII表 打印
9.dir() 目录
print(dir(all))
运行结果:
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__'] Process finished with exit code 0
10.divmod() 取商和余
print(divmod(4,2)) # 可以用来做分页功能,例如:一共4页,每页分了2行字,一共分了2页。
运行结果:
(2, 0)
Process finished with exit code 0
11.eval() 提取字符串中的数据结构,还可以把字符串中的表达式进行运算
12.hash() 可hash的数据类型,为不可变数据类型
print(hash("113123123465")) print(hash("456asdfa4561sdf1a456sad4f"))
运行结果:
714133531
-1932136269
Process finished with exit code 0
13.help() 查看帮助
14.hex() 十进制转十六进制
15.oct() 十进制转八进制
16.isinstance() 判断类型
print(isinstance(1,int))
运行结果:
True
Process finished with exit code 0
17.locals() 打印当前路径 (局部)
18.globals() 打印路径(当前文件的路径)
19.max() 取最大值
20.min()取最小值
作者:我就是喜欢你
链接:https://www.pythonheidong.com/blog/article/11442/464fe78ef2aeefe4efd6/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!