# 09-int 数字型「Dannie」

AI悦创原创
• Python 1v1
• Python 基础笔记
• Python 1v1
• Python 基础笔记

1. int：整数类型
2. float：浮点数类型

## # 2. 数字型运算特点

### # 2.1 Pycharm 编写

``````a = 1
b = 3
r = a + b
print(r)

a = 1
b = 3
print(a + b)

print(1 + 3)
``````

### # 2.2 Ipython 简写

ipython 用于快速测试代码：

``````In [2]: 1 + 3
Out[2]: 4
``````

### # 2.3 Pycharm 编写代码并找规律

``````a = 1
b = 2
print(a + b)

a = 1
b = 3.0
print(a + b)

a = 9
b = 3
print(a - b)

a = 9.0
b = 3
print(a - b)

a = 2
b = 3
print(a * b)

a = 2
b = 3.0
print(a * b)

a = 9
b = 3
print(a / b)
``````

``````3
4.0
6
6.0
6
6.0
3.0
``````

### # 2.4 ipython 编写代码并找规律

``````In [4]: 1 + 2
Out[4]: 3

In [5]: 1 + 2.0
Out[5]: 3.0

In [6]: 3 - 2
Out[6]: 1

In [7]: 3.0 - 2
Out[7]: 1.0

In [8]: 2 * 3
Out[8]: 6

In [9]: 2 * 3.0
Out[9]: 6.0

In [10]: 9 / 3
Out[10]: 3.0

In [11]:
``````

### # 2.5 结论

• 如果其中有一个数据类型是浮点数，最后的结果就是浮点数
• 除法涉及精度问题，所以最后是浮点数。

## # 4. 20220928 作业

### # 4.1 Dannie 答案

#### # 4.1.1 Q1✅

``````a=26
b=a//10
print(b)

c=a%10
print(c)

d=b+c
print(d)
``````

``````In [7]: a = 26

In [8]: b = a // 10

In [9]: c = a % 10

In [10]: d = b + c

In [11]: d
Out[11]: 8
``````

#### # 4.1.2 Q2✅

``````a=26
b=a//10
print(b)

c=a%10
print(c)

d=b+c
print(d)

e=c*10+b
print(e)
``````

``````In [12]: e = c * 10 + b

In [13]: e
Out[13]: 62
``````

#### # 4.1.3 Q3✅

``````a=826
b=a//100
print(b)
c=(a-b*100)//10
print(c)
d=a-(b*100+c*10)
print(d)

e=b*100+d*10+c
print(e)
``````

``````In [14]: a = 826

In [15]: b = a // 100

In [16]: c = a % 100 // 10

In [17]: e = a % 100 % 10

In [18]: b + c + e
Out[18]: 16

In [19]: e * 100 + c * 10 + b
Out[19]: 628
``````

## # 5. 比较运算符

``````In [20]: 1 >= 1
Out[20]: True

In [21]: 2 >= 1
Out[21]: True

In [22]: 2 >= 1
Out[22]: True
``````

## # 6. 赋值运算符

``````In [24]: a = 1

In [25]: a = a + 10

In [26]: a
Out[26]: 11

In [27]: a += 10 # a = a + 10

In [28]: a
Out[28]: 21
``````

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度