# li = [11,22,33,44]# def f1(arg):# arg.append(55)# # li = f1(li)# f1(li)# print(li) # 不太重要# 是否可以被执行被调用# def f1():# pass## f1()# f2 = 123## f2()# print(callable(f1)) # print(callable(f2))# callable() # ascil码转换列表 相互转换对应关系# 数字转换成字母# r = chr(65)# print(r)# A # 字母转换成数字# n = ord("a")# print(n)# 97 #生成字母随机验证码# import random# li = []# for i in range(6):# temp = random.randrange(65,91)# c = chr(temp)# li.append(c)# result = "".join(li)# print(result) # 生成随机数字# import random# 1 <= i <5# i = random.randrange(1,5)# i = random.randrange(65,91)# c = chr(i)# print(c) # 生成字母# import random# li = []# for i in range(6):# temp = random.randrange(65,91)# c = chr(temp)# li.append(c)# result = "".join(li)# print(result) #生成字母数字,随机生成数字字母# import random# li = []# for i in range(6):# if i ==2 or i ==4:# num = random.randrange(0,10)# li.append(str(num))# else:# temp = random.randrange(65,91)# c = chr(temp)# li.append(c)# result = "".join(li)# print(result) #生成字母数字,随机生成数字字母不限制位数# import random# li = []# for i in range(6):# r = random.randrange(0,5)# if r ==2 or r ==4:# num = random.randrange(0,10)# li.append(str(num))# else:# temp = random.randrange(65,91)# c = chr(temp)# li.append(c)## result = "".join(li)# print(result) # compile()编译代码# python s1.py# 1、读取文件内容,str到内存# 2、python内部,把字符串-》编译成 -》特殊代码# 3、执行代码# s = "print(123)"# 编译 single(单行),eval(表达式),exec(python)# 将字符串编译成python代码# r = compile(s,"<string>","exec")# print(r) #<code object <module> at 0x101b1f5d0, file "<string>", line 1># exec 执行python代码# exec(r) # 123# eval() # 执行python代码,接收:代码或者字符串# exec("7+8+9")# eval 执行表达式,并获取结果# ret = eval("7+9+8")# print(ret) # 执行python代码,继续接收代码或者字符串# exec("7+9+8")#执行表达式,并获取结果# ret = eval("7+9+8")# print(ret) # 快速查看,对象提供了哪些功能# print(dir(dict))# 查看帮助# help(list) # 共:97,每页显示10条,需要多少页# r = divmod(97,10)# print(r) 商9 余数7# r = divmod(100,10)# print(r[0]) 商# print(r[1]) 余数 # s = "alex" 对象,"alex" => str # s = [11,11,11]# isinstance 用于判断,对象是否是某个类的实例# r = isinstance(s,list)# print(r) 返回True # filter,map # def f1(args):# result = []# for item in args:# if item > 22:# result.append(item)# return result## li = [11,22,33,44,55]# ret = f1(li)# print(ret) 33,44,55 # filter (函数,可迭代的对象)# def f2(a):# if a > 22:# return True# li = [11,22,33,44,55]# ret = filter(f2,li)# print(list(ret)) # filter内部,循环第二个参数# result = []# for item in 第二个参数# r = 第一个参数(item)# if r:# result(item)# return result# filter , 循环第二个参数,让每个循环元素执行 函数(第一个参数),如果函数返回值True,表示元素合法 # ret = filter(f2,li)# print(list(ret)) # 自动return# f1 = lambda a: a >30# ret = f1(90)# print(ret) True # filter 函数返回True,将元素添加到结果中## li = [11,22,33,44,55]# result = filter(lambda a:a > 33,li)# print(list(result)) # li = [11,22,33,44,55]# def f1(args):# result = []# for i in args:# result.append(100+i)## return result# r = f1(li)# print(list(r)) # map 将函数返回值添加到结果中# li = [11,22,33,44,55]# map(函数,可迭代的对象(可以for循环的东西))# def f2(a):# return a + 100# result = map(f2,li)# result = map(lambda a: a +200,li)# print(list(result))# result = map(lambda a:a + 200,li)# print(list(result)) # len# s = "李杰"# print(len(s))## s = "李杰"# b =bytes(s,encoding=‘utf-8‘)# print(len(b)) # 2的10次方# r = pow(2,10)# print(r) # 反转# li = [11,22,1,1]# li.reverse()# reversed(li)# print(li) # 四舍五入# r = round(1.8)# print(r) # 切片# s = "sssssssssss"# print(s[0:2:2]) # 排序# li = [11,22,3,1,2]# li.sort()# print(li) # zip# l1 = ["qq",11,22,33]# l2 = ["aa",11,22,33]# l3 = ["zz",11,22,33]# r = zip(l1,l2,l3)# # print(list(r))# temp = list(r)[0]# ret = ‘ ‘.join(temp)# print(ret)
时间: 2024-10-08 10:29:49