内置函数操作
#!usr/bin/env python
# -*- coding:utf-8 -*-
# 1.locals()和globals()
# def func():
# x=1
# y=2
# print(locals())
# print(globals())
# func() # 2.eval,exec,和compile
# print(123)
# "print(456)"#字符串
# eval("print(456)")#吧字符串转换成python代码去执行(有返回值)
# exec("print(7889)")#吧字符串转换成python代码去执行(无返回值)
# num = eval('4+5+6')#执行了,有返回值
# print(num)
#
# num = exec('4+5+6')#执行了,没有返回值
# print(num)
# compile#做编译
# com=compile('1+2+3','',mode = 'eval')#节省时间
# print(eval(com))
# print(eval('1+2+3'))#这句效果和上面的compile()效果一样 # 3.print
# print('123',end='')#不换行
# print('456',end='') # print(1,2,3)
# print(1,2,3,4,5,6,sep=',') # print()函数的小例子
# import time
# import sys
# for i in range(0,101,2):
# time.sleep(0.1)
# char_num = i//2 #打印多少个#
# per_str = '%s%% : %s\n' % (i, '*' * char_num) if i == 100 else '\r%s%% : %s'%(i,'*'*char_num)
# print(per_str,end='', file=sys.stdout, flush=True) # import sys
# for i in range(0, 101, 2):
# time.sleep(0.1)
# char_num = i // 2
# per_str = '\r%s%% : %s' % (i, '*' * char_num)
# print(per_str, file=sys.stdout, flush=True) # 4.input()
# 5.type()
# 6.hash
# print(hash('asdsffd'))#一开始几个都是不变的,,然后重新运行一次就变了
# print(hash('asdsffd'))
# print(hash('asdsffd'))
# print(hash('asdsffd'))
# print(hash('asdsffd'))
# print(hash((1,2,3,4))) # 7.open
# r,w,a,r+,w+,a+(都可以加b)
# f=open('tmp','r+')#r+打开文件
# print(f.read(3))#如果读了在写,追加
# f.seek(5)#如果seek指定了光标的位置,就从该位置开始覆盖这写
# f.write('aaaaaa')#如果直接写,从头覆盖
# f.close() # 8.__import__()
# import os
# import sys
# import time # 9.callable:查看能不能调用
# print(callable(123))#数字不能调用结果就是False
# print(callable(open))#函数可以调用就返回True # 10.dir 查看数据类型的方法
# print(dir(__builtins__))#看着报错,,但其实不报错
# print(dir(int))
# print(dir(list))
# print(dir(0))#和int一样
# print(set(dir(list))-set(dir(tuple)))
# 11.
# num1=int(123)
# num2=int(12.3)#强制转换成int类型
# print(num1,num2)
# 12.取商/余
# print(divmod(7,3))
# 13.计算最小值
# print(min(1,2,3,4))
# print(min([5,6]))
# 13.计算最大值
# print(max(1,2,3,4))
# print(max([5,6])) # 14.sum求和
# print(sum(1,2,3,4))#出错了,参数是序列,散列不行
# print(sum([5,6]))
# print(sum((1,2,3,4))) # 以下的两个方式是一样的
# print(1+2)
# print(int(1).__add__(2)) # 15.round精确度
# print(round(3.1415926,2))#保留两位 # 16.pow()幂运算
# print(pow(2,3))
# print(2**3) # 17.和数据结构相关的
# 1.reversed()顺序的反转
# l=[1,2,3,4]
# print(list(reversed(l)))#是生成了一个新的列表,没有改变原来的列表(以后能不用reversed就不用reversed,用reverse)
#
# # l.reverse()#在现在的列表的基础上修改了,修改的是原来的列表
# print(l) # 2.slice切片
# 3.format()#除了格式化以外的作业
# print(format('test','<20'))
# print(format('test','>40'))
# print(format('test','^40')) # 4.bytes
s='你好'
# sb=bytes(s,encoding='utf-8')
# print(sb)
# print(sb.decode('utf-8')) # sb2=bytearray(s,encoding='utf-8')
# sb2[0]=229 #修改 了解就好
# print(sb2.decode('utf-8'))
# print(sb2)
# print(sb2[0]) # 5.repr
# print(repr('1234'))
# print(repr(1234))
# print('name:%r'%('egon'))#你怎么传进去的就按什么格式打印出来了 # 6.set和frozenset(不可变的集合)就像list和tuple # 7.enumerate
# l=['a','b']
# for i in enumerate(l):
# print(i)
#
# for i ,j in enumerate(l):
# print(i,j) # 8.all和any
# print(all([1,2,3]))
# print(all([0,2,3]))#因为0是False
#
# print(any([1,2,3]))
# print(any([0,2,3])) # 9.zip()
# l=[1,2,3]
# l2=[4,5,6,7,8]
# print(zip(l,l2))
# print(list(zip(l,l2)))
# l3={'k':'v'}
# print(list(zip(l,l3))) # 10.sort和sorted
# l=[1,3,5,-2,-6]
# l.sort()
# print(l)
# l2=[1,3,5,-2,-6]
# print(sorted(l2))
# print(sorted(l2,key=abs))
# print(sorted(l2,key=abs,reverse=True))#默认从小到大排序,修改为True,则从大到小排序 # 11.map():我要对我的列表当中的每一个值去做函数里面的操作
# l=[1,2,3,4,5]
# def pow2(x):
# return x*x
# print(list(map(pow2,l))) # 12.filter():从一个列表当中找到所有符合筛选条件的,在组成一个新列表
# def aaa(x):
# return x%2==1
# ret=list(filter(aaa,[1,2,54,3,6,8,17,9]))
# print(ret)
https://www.processon.com/mindmap/59803759e4b06a973c4dc657