# # 内置函数format的用法
# a=100
# print(format(a,'b')) # 将十进制a转为二进制,输出:1100100
# print(format(a,'08b')) # 将十进制a转为8进制,不够8位用0补齐,够8位不管,输出:01100100;这个之后和子网掩码有用
# print(format(a,'o')) # 将a转为8进制,输出:144
# print(format(a,'x')) # 将a转为十六进制,输出:64
# ord :查看一个字在unicode中的码位是多少
b='国'
print(ord(b)) # 输出:22269
# chr:unicode中码位对应的文字符号是多少
print(chr(22269)) # unicode码位22269对应文字是:国
# 输出所有的unicode对应文字
# for i in range(65525):
# print(chr(i)+" " ,end="")
# enumerate,all ,any
# all 首先all里面参数是可迭代的,all可以理解为“and”,当所有都是有值才返回True
print(all([1,2,3])) # 返回:True
print(all(["",0,None])) # 返回:False,这个3个值都代表空,没有
# any 内容也是可迭代的,any可以理解为or,只要有一个为True,则返回True,所有都是False才返回False
print(any(["",0,1])) # 返回:True
print(any(["",0,None])) # 返回:False
# enumerate:输出可迭代对象及其下标
l = ['张三','李四','王五']
for i in enumerate(l):
print(i) # 输出的是元组:(0, '张三') (1, '李四') (2, '王五')
# 下面这样写更好用,跟字典很像
for index,item in enumerate(l):
print(index,item) # 输出:0 张三 1 李四 2 王五
# 上面这个我们之前是这样实现的
for i in range(len(l)):
print(i,l(i)) # 输出:0 张三 1 李四 2 王五
# hash,
s='哈哈哈'
print(hash(s)) # 返回一定是个数字 → 转化为内存地址,然后进行数据存储 → 字典,元组,字符串都是可哈希的
# 这里输出:-1159055969,每次打印数字都不一样
# dir,当前数据能执行哪些操作
s='哈哈哈'
print(dir(s))
# 打印:['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']