Python算术运算符

简介: 【6月更文挑战第27天】Python算术运算符。

在了解了算术运算符之后编写实例进行验证,在basis目录下新建文件,命名为arithmetic.py,学习Python算术运算符的操作,在PyCharm中编写代码。
operand_a = 5
operand_b = 2
operand_c = 0

加法运算

operand_c = operand_a + operand_b
print("{} + {} = {}".format(operand_a, operand_b, operand_c))

减法运算

operand_c = operand_a - operand_b
print("{} - {} = {}".format(operand_a, operand_b, operand_c))

乘法运算

operand_c = operand_a operand_b
print("{}
{} = {}".format(operand_a, operand_b, operand_c))

除法运算

operand_c = operand_a / operand_b
print("{} / {} = {}".format(operand_a, operand_b, operand_c))

取余运算

operand_c = operand_a % operand_b
print("{} % {} = {}".format(operand_a, operand_b, operand_c))

取整运算

operand_c = operand_a // operand_b
print("{} // {} = {}".format(operand_a, operand_b, operand_c))

乘幂运算

operand_c = operand_a operand_b
print("{}
{} = {}".format(operand_a, operand_b, operand_c))

相关文章
|
2月前
|
Python
python算术运算符和反算术运算符的应用
算术运算符包括加法(+), 减法(-), 乘法(*), 除法(/), 取模(%), 整除(//)和幂运算(**); 反算术有取负数(-)和取倒数(1/a)。以下是Python示例代码: ```markdown a = 10 b = 5 c, d, e, f, g, h, i = a + b, a - b, a * b, a / b, a % b, a // b, a ** b j, k = -a, 1 / a ``` 执行这些运算后,会得到相应的计算结果。
23 2
|
9月前
|
Python
python之算术运算符,复合运算符,逻辑运算符,比较运算符的定义及其使用方法
python之算术运算符,复合运算符,逻辑运算符,比较运算符的定义及其使用方法
|
2月前
|
Python
python 中错误的算术运算符
【5月更文挑战第20天】
22 5
|
2月前
|
Python
python的算术运算符
python的算术运算符
17 0
|
2月前
|
Python
Python算术运算符,新手一看就会
Python算术运算符,新手一看就会
15 0
|
2月前
|
Python
Python入门02 算术运算符及优先级
Python入门02 算术运算符及优先级
|
7月前
|
Python
python算术运算符和反算术运算符的应用
python算术运算符和反算术运算符的应用
|
2月前
|
人工智能 测试技术 Python
软件测试/人工智能|Python算术运算符:入门指南
软件测试/人工智能|Python算术运算符:入门指南
56 0
|
11月前
|
Python
Python运算符(一):算术运算符
Python运算符(一):算术运算符
|
11月前
|
Java C++ Python
Python/算术运算符详解
Python/算术运算符详解