#取绝对值 #print(abs(-1)) #对序列中的元素进行bool运算,如果可迭代对象为空也返回True # print(all((1,23,))) # print(all({"name":None})) # print(all('')) #对序列中的元素进行bool运算,如果可迭代对象中有一个为真,返回True # print(any([0,1,2,3])) # print(any([0,''])) #空,None,0的布尔值为false,其余都为True #print(bool('')) #十进制转换为二进制 #print(bin(3)) # name="你好" 以字节流的形式交互数据 # print(bytes(name.encode('gbk')).decode())#以gbk的格式进行解码 # print(bytes(name,encoding='utf-8'))#已utf-8的格式进行编码 #显示数字对应的ASCII值 #print(chr(90)) # # # #打印对象下面的方法 # print(dir(list)) #返回商和余数的元祖 # print(type(divmod(10,3))) # print(divmod(10,3)) #eval把字符串中的表达式进行数学运算,把字符串中的数据结构提取出来 # dic={'name':'alex'} # dic_str=str(dic) # print(eval(dic_str)['name']) #可hash的数据类型即不可变数据类型,不可hash的数据类型即可变数据类型 #print(hash("123")) # name="alex" # print(hash(name)) # print(hash(name)) # # # name='sb' # print(hash(name)) # print(bin(10))#十进制转二进制 # print(hex(12))#10进制===>十六进制 # print(oct(12))#10进制==>八进制 #判断当前对象是否属于当前类的实例 #print(isinstance(1,int)) #打印当前文件的所有全局变量 #name="hahhah" # print(globals()) # print(__file__) #locals打印当前局部变量,字典形式显示 # def test(): # age=19 # print(locals()) # test() # l=[100,0,10] # print(max(l)) # print(min(l)) # if __name__=='__main__': # pass #zip方法返回序列的对应元祖 # print(list(zip(('a','b','c'),(1,2,3)))) # print(list(zip(('a','b','c'),(1,2,3,5)))) # # # p={'name':'alex','age':18,'gender':'none'} # print(list(zip(p.keys(),p.values()))) # # # print(list(zip("hello",'12345'))) # print(list(zip({1,2,3},{'a','b','c'}))) #print(list(zip([1,2,3],['shsh','skjsjk']))) #max函数处理的可迭代对象,相当于一个for循环取出每个元素进行比较,注意,不同类型之间不能进行比较 #每个元素间进行比较,是从每个元素的第一个位置依次比较,如果这一个位置分出大小,后面的都不需要比较了,直接的出这两元素的大小 age_dict={'age1':18,'age4':20,'age3':100,'age2':30} # print(max(age_dict.values()))比较的是values,但不知道那个key对应的 # print(min(age_dict.values())) #默认比较的是字典的key #print(max(age_dict)) # # for item in zip(age_dict.values(),age_dict.keys()): # print(item) # # print(max(zip(age_dict.values(),age_dict.keys())))#结合zip使用 # print(max((100,10),(200,10))) # l=[(5,'e'),(1,'b'),(3,'a'),(4,'d')] # print(max(l)) # # # #ll=['a12','b33','c55',100]不同类型之间不能进行比较 # ll=['a10','a11','a2'] # print(max(ll)) # # # people=[{"name":"alex","age":10000},{"name":"han","age":1000},{"name":"ou","age":18}] # # print(max(people,key=lambda x:x['age'])) # ret=[] # for item in people: # ret.append(item['age']) # print(ret) #print(ord('a')) #**次方 # print(pow(10,3))#10**3 # print(pow(3,3,2))#3**3%2 #四舍五入 #print(round(3.5)) #print(set('hello')) # l="hello" # s1=slice(3,5,1) # print(l[s1]) # print(s1.start) # print(s1.step) # print(s1.stop) l=[3,2,1,5] #ll=[3,2,'a',5,6]排序本质就是在比较大小,不同类型之间不可以比较大小 # l.sort() # print(l) # print(sorted(l)) # print(sorted(l,reverse=True)) # # # # people=[{"name":"alex","age":10000},{"name":"han","age":1000},{"name":"ou","age":18}] # print(sorted(people,key=lambda p:p['age'])) # # # name_dic={ # 'alex' # :200, # 'wupei':300, # 'abyuanhao':900 # } # print(sorted(zip(name_dic.values(),name_dic.keys()))) # # print(sorted(name_dic,key=lambda key:name_dic[key])) # print(str({1,2})) # # res=str({'name':"alex"}) # print(eval(res)) # # # l=[1,2,3] # print(sum(range(5))) # print(type(1)) # msg='123' # if type(msg) is str: # msg=int(msg) # print(msg+1) # def test(): # name="dhdhfjqfh" # #print(locals()) # print(vars()) # test() #print(vars(int)) import test test.say() #import 'test' 报错 # moudle_name='test' # m=__import__(moudle_name) # m.test()