常用内置函数

# 1.map()  映射
l = [1,2,3,4]
map(lambda x:x+1,l)  # 循环获取列表中每个元素并传递给匿名函数保存返回值

# 2.zip()  拉链
l = [11, 22, 33, 44, 55, 66, 77]
name_list = ['jason', 'kevin', 'tony', 'jerry']
l1 = [1, 2, 3, 4, 5, 6, 7]
l2 = [8, 7, 6, 4, 3, 2, 1]
# new_list = []
# for i in range(len(l)):
#     new_list.append((l[i],name_list[i]))
# print(new_list)
res = zip(l, name_list, l1, l2)
print(list(res))

# 3.max与min  max求最大值 min求最小值
# l = [11, 22, 33, 44, 55, 66, 77]
# print(max(l))
# print(min(l))

d = {
    'jason':3000,
    'Bevin':1000000,
    'Ascar':10000000000,
    'aerry':88888
}
# def index(key):
#     return d[key]
# print(max(d,key=lambda key:d[key]))  # for循环先取值 之后再比较大小
"""
A-Z  65-90
a-z  97-122
"""
# print(min(d,key=lambda key:d[key]))  # jason

# 4.filter  过滤
l = [11, 22, 33, 44, 55]
res = filter(lambda x: x > 30, l)
print(list(res))  # [33, 44, 55]

# 5.reduce  归总
from functools import reduce
d = [11, 22, 33, 44, 55, 66, 77, 88, 99]
res = reduce(lambda x, y: x + y, d)
res1 = reduce(lambda x, y: x + y, d, 100)  # 还可以额外添加元素值
print(res)

# 1.abs()  绝对值
# print(abs(123))
# print(abs(-123))
# 2.all()  any()
# l = [11,22,33,0]
# print(all(l))  # 所有的元素都为True结果才是True
# print(any(l))  # 所有的元素只要有一个为True结果就为True
# 3.bin() oct() hex()  进制数
# print(bin(123))
# print(oct(123))
# print(hex(123))
# 4.bytes() str()
# res = '金牌班 最牛逼'
# res1 = bytes(res,'utf8')
# print(res1)
# res2 = str(res1,'utf8')
# print(res2)
# res1 = res.encode('utf8')
# print(res1)
# res2 = res1.decode('utf8')
# print(res2)
# 5.callable()  是否可调用(能不能加括号运行)
# s1 = 'jason'
# def index():
#     pass
# print(callable(s1),callable(index))  # False True
# 6.chr()  ord()
# print(chr(65))  # 根据ASCII码转数字找字符
# print(ord('A'))  # 65
# 7.complex()  复数
# print(complex(123))  # (123+0j)
# 8.dir()  查看当前对象可以调用的名字
# def index():
#     pass
# print(dir(index))
# print(index.__name__)
# 9.divmod()
# print(divmod(101,10))
"""总数据100 每页10条  10页"""
"""总数据99  每页10条  10页"""
"""总数据101 每页10条  11页"""
# num,more = divmod(233,10)
# if more:
#     num += 1
# print('总共需要%s页'%num)
# 10.eval()只能识别简单的语法  exec()可以识别复杂语法  都是将字符串中的数据内容加载并执行
# res = """
# 你好啊
# for i in range(10):
#     print(i)
# """
# res = """
# print('hello world')
# """
# eval(res)
# exec(res)
# 11.isinstance()  判断是否属于某个数据类型
# print(isinstance(123,float))  # False
# print(isinstance(123,int))  # True
# 12.pow()
# print(pow(4,3))
# 13.round()
# print(round(4.8))
# print(round(4.6))
# print(round(8.5))
# 14.sum()
# l = [11,22,333,44,55,66]
# print(sum(l))
posted on 2021-11-22 15:50  狼行千里吃肉  阅读(54)  评论(0)    收藏  举报

import time with open('a.txt', 'rb') as f: f.seek(0, 2) while True: line = f.readline() if len(line) == 0: # 没有内容 time.sleep(0.5) else: print(line.decode('utf-8'), end='')