2018/11/11(python)

---恢复内容开始---

1.内置函数

zip()

#例1
t=zip(('b','a','c'),(1,2,3))      #zip需要两个序列,一一匹配
print(list(t))


#例2
p={'name':'alex','age':'18','gender':'no'}
s=zip(p.keys(),p.values())
print(list(s))


#例3
print(list(zip('hello','54321')))

max()

min()

#应用1(与zip连用)
age={'age_1':50,'age_2':10,'age_3':150,'age_4':510,'age_5':30}
print(max(zip(age.values(),age.keys())))
#例2
p=[{'name':'alex','age':18,'gender':'no'},
   {'name':'bob','age':17,'gender':'no'},
   {'name':'joun','age':25,'gender':'no'},
   {'name':'helen','age':18,'gender':'no'}]
print(max(p,key=lambda dict:dict['age']))

ord()      <==显示字符在ASCII中数字

print(ord('a'))

reversed()    <==反转

round()    《==四舍五入

slice()      <==切片

a='qwertyu'
b=slice(3,5)
print(a[b])

sorted()    <==排序

#
p=[{'name':'alex','age':18,'gender':'no'},
   {'name':'bob','age':17,'gender':'no'},
   {'name':'joun','age':25,'gender':'no'},
   {'name':'helen','age':18,'gender':'no'}]
print(sorted(p,key=lambda dict:dict['age']))

import与_import_1区别

import不能导入字符串模块,_import_可以

 

posted on 2018-11-11 21:57  hcy12  阅读(97)  评论(0编辑  收藏  举报

导航