python中变量类型转换

>>> a = 5
>>> a
5
>>> type(a)
<class 'int'>
>>> b = float(a)
>>> b
5.0
>>> type(b)
<class 'float'>
>>> c = 5.3
>>> c
5.3
>>> type(c)
<class 'float'>
>>> d = int(c)
>>> d
5
>>> type(d)
<class 'int'>
>>> e = 5
>>> e
5
>>> type(e)
<class 'int'>
>>> f = str(e)
>>> f
'5'
>>> type(f)
<class 'str'>
>>> g = "5"
>>> g
'5'
>>> type(g)
<class 'str'>
>>> h = int(g)
>>> h
5
>>> type(h)
<class 'int'>

 

posted @ 2020-12-17 18:31  小鲨鱼2018  阅读(144)  评论(0编辑  收藏  举报