我的python之路(三):什么是代码与python的基本类型

3.1 什么是代码?

1、什么是代码

代码是现实世界事物在计算机世界中的映射2019-05-01

2、什么是写代码

写代码是将现实世界中中的事物用计算机语言来描述 

3.2 python 数字:整形与浮点型

number:数字(整数、小数)

在Python中:整数用int 表示;浮点数用float表示。

其他语言中浮点数还有单精度与双精度的划分:单精度(float)、双精度(double),双精度比单精度精度要高,但在python中,没有这种划分,python的浮点数就是双精度。

其他语言中整数有:short ,int , long的划分,Python没有。

用type 函数可以看出这个数字属于哪一类:

>>> type(1)
<class 'int'>
>>> type(-1)
<class 'int'>
>>> type(1.1)
<class 'float'>
>>> type(1.111111)
<class 'float'>
>>> type(1+1.0)
<class 'float'>
>>> type(1+0.1)
<class 'float'>
>>> type(1+1.0)
<class 'float'>
>>> type(1*1)
<class 'int'>
>>> type(1*1.0)
<class 'float'>
>>> type(2/2)
<class 'float'>注意

补充:单斜杠“/”与双斜杠“//”的区别

单斜杠是除法,是自动的转成浮点数,双斜杠是整除

>>> 2/2
1.0
>>> 2//2
1
>>> 1/2
0.5
>>> 1//2
0

3.3 10、2、8、16进制

10进制,2进制,8进制,16进制

猜你喜欢

转载自www.cnblogs.com/haohanTL/p/10800401.html