geekdoc-python-zh/docs/py4b/python-operators.md

49 lines
1.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Python 运算符
> 原文:<https://www.pythonforbeginners.com/basics/python-operators>
## 算术运算符
Python 包括+、-、*、/、%(模数)和**(取幂)运算符
假设变量 a 保存 10变量 b 保存 20则:
**运算符描述示例**
+加法 a + b 会给出 30
–减法 b 会给出-10
*乘法 a * b 会给出 200
/除法 b / a 会给出 2
%模 b % a 会给出 0
**指数 a**b 会给出 10 的 20 次方
//地板除法 9//2 等于 4 且 9.0//2.0 等于 4.0
## 比较运算符
基本比较运算符,如==、 =,等等,用于所有
方式的值。
数字、字符串、序列和映射都可以进行比较。
下表显示了比较运算符的列表。
**运算符描述**
<小于
< =小于等于
==等于
>大于
> =大于等于
=不等于< >不等于
## 逻辑运算符
在决策结构中使用时,逻辑运算符 and 和 or 也会返回一个布尔值。
有三种逻辑运算符:and、or 和 not。
例如,只有当 x 大于 0 且小于 10 时x > 0 且 x < 10 才成立
**运算符描述**
与逻辑
或逻辑
非逻辑非