python函数第6天(day 25)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python函数第6天(day 25)相关的知识,希望对你有一定的参考价值。
内置 函数:
# print(abs(-1)) # print(abs(0)) # # # print(all(‘ ‘)) # print(all((1,‘ ‘,2,None))) # print(all(i for i in range(1,10))) # print(any([])) # print(any([None,0,‘‘,{},1])) # res=sum(i for i in range(3)) # print(res) # print(bin(3)) # # # print(bool(0)) # print(bool(None)) # print(bool(‘‘)) # # # print(bytes(‘hello‘,encoding=‘utf-8‘)) # def test(): # pass # print(callable(test)) # print(callable(sum)) # print(chr(67)) # print(chr(65)) # # print(ord(‘A‘)) #数据类型 #int # num=1 #num=int(1) # print(type(num)) #查看num的类型 # print(isinstance(num,int)) #判断num是否为int类型,这个才是判断类型的 # print(num is 1) # is 是身份运算,根据id去判断身份,不是判断类型的,适用于所有数据类型,字典啊,列表啊,集合啊, # float # bool # complex # str # x=‘asdfa‘ #x=str(‘asdfa‘) # print(str(1)) # print(str({‘a‘:1})) # list # x=[] # x=list(i for i in range(10)) list函数括号里面的要是一个可迭代的对像,是把任何可迭代的对像,变成一个列表 # print(x) # tuple # dict # d={‘a‘:1} # d=dict(x=1,y=2,z=3) # print(d) set # s={1,2,3,4,4} # print(s) # s.add(5) # print(s) # # frozenset #不可变集合 # f=frozenset({1,2,3,4}) # print(type(f)) # x=complex(1-2j) # print(x.real) # print(x.imag) # x=1-2j # print(x.real) # print(x.imag) l=[] # print(dir(l)) # print(help(sum)) # print(divmod(100,33)) # # for i in enumerate([‘a‘,‘b‘,‘c‘,‘d‘]): # print(i) # for i in enumerate({‘x‘:1,‘y‘:2}): # print(i) # s=‘hello‘ # print(hash(s)) # s=‘h‘ # print(hash(s)) # print(hex(10)) # print(hex(11)) # # print(id(‘asdf‘)) # a=1 # b=2 # print(id(a)) # print(id(b)) # print(a is b) # x=‘a‘ # y=‘a‘ # print(id(x)) # print(id(y)) # print(x is y) #max和min # print(max(1,2,3,4,10,3)) # print(min(1,2,3,4,10,3)) salaries={ ‘egon‘:3000, ‘alex‘:100000000, ‘wupeiqi‘:10000, ‘yuanhao‘:250 } def get_value(k): return salaries[k] #匿名函数 # lambda k:salaries[k] # f=lambda k:salaries[k] 匿名函数也可以赋值一个名字,但是这便违反了匿名的初衷 # print(f) # print(f(‘egon‘)) # print(max(salaries)) # print(max(salaries,key=get_value)) # print(max(salaries,key=lambda k:salaries[k])) # print(min(salaries,key=lambda k:salaries[k])) #拉链 # l1=[1,2,3,4] # s=‘hel‘ # for i in zip(l1,s): # print(i) # print(salaries.keys(),salaries.values()) # z=zip(salaries.values(),salaries.keys()) # print(z) # for i in z: # print(i) # print(max((1,‘a‘),(1,‘b‘))) # l=[3,4,1,0,9,10] # print(sorted(l)) #返回值是列表,默认是升序 # print(sorted(l,reverse=True)) #降序排列 # # s=‘hello abc‘ # print(sorted(s)) # # salaries={ # ‘egon‘:3000, # ‘alex‘:100000000, # ‘wupeiqi‘:10000, # ‘yuanhao‘:250 # } # print(sorted(salaries)) #默认是按照字典salaries的key去排序的 # # print(sorted(salaries,key=lambda x:salaries[x])) # print(sorted(salaries,key=lambda x:salaries[x]),reverse=True) #排序且修改 # # l=[3,2,0,10] # l=sorted(l) # # print(l) # map:映射 l=[1,2,3,7,5] # x=[i**2 for i in l] # print(x) m=map(lambda item:item**2,l) # print(m) # # for i in m: # # print(i) # print(list(m)) # name_l=[‘alex‘,‘zhengjiangF4‘,‘yuanhao‘,‘wupeiqi‘] # m=map(lambda name:name+‘SB‘,name_l) # print(list(m)) from functools import reduce #合并 l=list(range(100)) # print(l) # print(reduce(lambda x,y:x+y,l,100)) # i=iter(l) # 100 next(i) --->100,0----->x,y-x+y-->100 # 100 next(i)---->100,1----->x,y--x+y-->101 # 101 next(i)----->101,2 # filter#过滤 # name_l=[ # {‘name‘:‘egon‘,‘age‘:18}, # {‘name‘:‘dragonFire‘,‘age‘:1000}, # {‘name‘:‘gaoluchuan‘,‘age‘:9000}, # {‘name‘:‘fsw‘,‘age‘:10000}, # ] # # f=filter(lambda d:d[‘age‘] > 100,name_l) # print(f) # for i in f: # print(i) #其他 # print(oct(10)) # print(pow(3,2,2)) # print(list(reversed([1,5,3,9]))) # print(round(10.3)) # print(round(10.5)) # print(round(10.6)) # print(round(10.9)) # slice # l=[1,2,3,4,5,6,7,9] # print(l[2:5:2]) # # # s=slice(2,5,2) # print(l[s]) # print(vars() is locals()) import time # time.sleep(3) print(time) m=__import__(‘time‘) print(m) m.sleep(3) #在面向对象里讲 classmethod staticmethod property delattr hasattr getattr setattr issubclass super #complie #eval #exec
以上是关于python函数第6天(day 25)的主要内容,如果未能解决你的问题,请参考以下文章
Python100天学习笔记Day25 JS面向对象及DOM