代码改变世界

Python基本数据类型

2019-01-22 10:23  janease  阅读(19)  评论(0)    收藏  举报

整数:int

浮点数:float

其他语言浮点数:单精度float,双精度double

其他语言整数:short,long,int

>>> type(2)
<class 'int'>
>>> type(-8)
<class 'int'>
>>>

 

>>> type(1.1)
<class 'float'>
>>> type(1.22225)
<class 'float'>

整型+整型=整型

整型+浮点=浮点

>>> type(1+1.2)
<class 'float'>
>>> type(1+2)
<class 'int'>
>>>

 

>>> type(1+1.0)
<class 'float'>

整型-整型=整型

整型-浮点=浮点

>>> type(1-1)
<class 'int'>

 

整型*整型=整型

整型*浮点=浮点

>>> type(1*8)
<class 'int'>
>>> type(1*1.1)
<class 'float'>

 

 

整型/整型=浮点

整型/浮点=浮点


>>> type(8/2)
<class 'float'>
>>> type(8/8)
<class 'float'>
>>>

整型//整型=整型

>>> type(8//2)
<class 'int'>
>>>