python Data type conversation

 

>>> repr(111.5)
'111.5'
>>> repr(10)
'10'
>>> int("11")
11
>>> long("22")
22L
>>> float("1.22")
1.22
>>> hex(19)
'0x13'
>>> oct(20)
'024'

 

 

>>> tuple("1,2,3,4,5")
('1', ',', '2', ',', '3', ',', '4', ',', '5')
>>> tuple("12345")
('1', '2', '3', '4', '5')
>>> tuple([1,2,3,4,5])
(1, 2, 3, 4, 5)
>>> tuple({1:2,3:4})
(1, 3)

 

>>> list((1,2,3,4,5))
[1, 2, 3, 4, 5]
>>> list("12345")
['1', '2', '3', '4', '5']
>>> list({1:2,3:4})
[1, 3]
>>>

 

>>> chr(65)
'A'
>>> ord("A")
65

 

#list to str 
>>> "".join(["a","1"])
'a1'

 

posted on 2016-12-26 10:33  大大的橙子  阅读(311)  评论(0编辑  收藏  举报

导航