python学习第四周之内置方法详解

1.python的内置方法有很多,用的时候可以自行百度,我只写几个我感兴趣的(任性。)

2.(1)bin(),将十进制转变为二进制

>>> bin(2)
'0b10'

 (2)chr(),查看数字所对应的字母,

>>> chr(98)
'b'

 (3)ord(),查看字母对应的数字

>>> ord('a')
97

 (4)hex(),转换成十六进制

>>> hex(255)
'0xff'

(5)oct(),转成成八进制

>>> oct(8)
'0o10'

 (6)下面看一下我感兴趣的sorted()方法

sorted可以排序,如下:

a={6:2,8:0,1:4,-5:6,99:11,4:22}
print(sorted(a.items()))  #sorted 对key排序,输出结果中只有key的排序结果,sorted(a.items()),按key来排序
print(sorted(a.items(),key=lambda x:x[1]))  #将字典按照value排序,x为每一个元素,即(-5,6)
print(a)

 完

 

posted @ 2019-08-20 17:45  凸凸yolotheway  阅读(113)  评论(0编辑  收藏  举报