print(bin(10)) #二进制
print(oct(10)) #八进制
print(hex(10)) #16进制
L1=[11,22,33,44]
L1.reverse()
print(L1) #[44, 33, 22, 11]
l = [1,2,3,4,5]
l2 = reversed(l)
print(l2) #<list_reverseiterator object at 0x000002778C05B390>
# 保留原列表,返回一个反向的迭代器
print(bytes('你好',encoding='GBK')) # unicode转换成GBK的bytes
print(bytes('你好',encoding='utf-8'))
#同时去掉*&和空格
str = "***hello world &&&&"
print(str.strip('*& ')) #hello world
#1到n之间的奇数
print(list(range(1,50,2)))
#去掉字符串中重复的字母
str1 = "hjklmbndbnwhjk"
print(str1.count('h'))
# print(set(str1))
list1=[]
[list1.append(x) for x in list(str1) if x not in list1]
print(''.join(list1)) #hjklmbndw
print("=======")
aa = ['a','b','c','d','e','a','b']
print()
bb =[]
ret = [bb.append(x) for x in aa if x not in bb]
print(bb)
#计算如下结果,为什么
a=10
b=20
def fun1(a,b):
print(a,b)
test = fun1(b,a) #20,10
print(test) #None,无返回值
#计算数字的和
s = '123.33shf234.66ujif478.863'
# 结果为:123.33+234.66+478.86
# 计算过程:
#第一种方法
from re import findall
ret = findall('\d+\.?\d{,2}',s)
print('+'.join(ret)) #123.33+234.66+478.86+3
#第二种方法
ret = [float(i) for i in ret] #eval(ret)
print(ret)
print(sum(ret))
#如果不使用@wapper装饰器,请在aa()之前加入一句代码,达到同样的效果
def wapper(func):
def inner(*args,**kwargs):
func(*args,**kwargs)
return inner
@wapper
def aa(arg):
print(arg)
# aa=wapper(aa)
aa(11)
#请处理文件中所有以T开头的行
#
# with open('filename')as f:
# for i in f:
# if i.startswith('T'):
# print(i)
#读登录文件夹中的代码,为这段代码画流程图
#m默写10个字符串内中的方法,描述作用
# strap()split()count()title,repalce,
#循环文件夹里面的所有文件,并把大小加起来
import os
#上级目录中所有的文件
f = os.listdir('..\python_Demo')
print(f)
list1 = []
for i in f:
ret = os.path.getsize(i)
list1.append(ret)
print(list1)
print(sum(list1))
print(os.getcwd())
f1= os.listdir('static')
print(f1) #['01.py', '03.jpg']
list2 = []
# for x in f1:
# ret1 = os.path.getsize(x)
# print(ret1) #875651,得到的是字节,除以1024,得到KB
# list2.append(ret1)
print(list2)
# 重命名文件名
# f1= os.listdir('static')
# print(f1) #['01.py', '03.jpg']
# for x in f1:
# print(x,type(x))
# name,houzui = x.rsplit('.')
# new_name = name+'附件'+'.'+houzui
# print(new_name,type(new_name))
#
# print(name,houzui)
# os.rename(x,new_name)
#
# print(list2)
# print(os.rename('231.py','abc1.py'))
#有四个数字1,2,3,4,能组成多少个互不相同切不重复的三位数字
count = 0
list3=[]
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i == j or i==k or j==k:
continue
count+=1
print(str(i)+str(j)+str(k))