input()
type()
len()
print()
enumerate()
list()
dict()
tuple()
set()
str()
int()
float()
bool()........
这些都是内置函数,不需要导入模块才能用
example:
排序:
sorted([5,6,7,234])
s='1122333453'
print(sorted(s,reverse=True)) #排序反转
ASCll码值转换:
print(ord('a'))
print(ord('A'))
print(chr(97)) #ascll码值得改变
map: 能够转化为list set tuple 类型
def bl(i):
return str(i).zfill(2)
l=[1,2,3,4,5,6,7,8,9]
res=list(map(bl,l)) #map是循环调用函数,保存函数里面的返回值
print(res)
exec:
类似于在线编程的原理,将敲在界面上的内容转化为字符串,字符串传入后台使用exec的函数转化,运行
my_code='''
def my():
print('运行my')
my()
'''
exec(my_code)
map与filter:
l=[1,2,3,4,5,6,7,8,9]
res=list(map(bl,l)) #map是循环调用函数,保存函数里面的返回值
f=list(filter(bl,l)) #filter是循环调用函数,保存函数里面返回值,如果返回的是真则保存
print(res)
print(f)
l='123456788'
def bl(i):
if i>'3':
return True
m=list(map(bl,l))
f=list(filter(bl,l))
print(m)
print(f)