# Python运算符

Python

## 序言

Python作为一门广泛应用的编程语言，其运算符更是不可或缺的一部分。运算符可以完成许多简单的任务，也可以实现更高级的计算。在Python中，运算符具有广泛的应用，包括数据类型转换、算术运算、比较运算、逻辑运算等等。本文将为您介绍Python中常用的运算符及其用法，帮助您更好地掌握Python编程。

## 一、数学运算符

### 加法运算符

``````a = 5
b = 10
c = a + b
print(c)  # 输出：15
``````

### 减法运算符

``````a = 5
b = 10
c = a - b
print(c)  # 输出：5
``````

### 乘法运算符

``````a = 5
b = 10
c = a * b
print(c)  # 输出：50
``````

### 除法运算符

``````a = 5
b = 10
c = a / b
print(c)  # 输出：0.5
``````

### 指数运算符

``````a = 5
b = 10
c = a ** b
print(c)  # 输出：1000
``````

## 二、比较运算符

### 等于运算符

``````a = 5
b = 5
c = a == b
print(c)  # 输出：True
``````

### 不等运算符

``````a = 5
b = 10
c = a!= b
print(c)  # 输出：False
``````

### 大于运算符

``````a = 5
b = 10
c = a > b
print(c)  # 输出：True
``````

### 小于运算符

``````a = 5
b = 10
c = a < b
print(c)  # 输出：False
``````

### 大于等于运算符

``````a = 5
b = 10
c = a >= b
print(c)  # 输出：True
``````

### 小于等于运算符

``````a = 5
b = 10
c = a <= b
print(c)  # 输出：True
``````

## 三、逻辑运算符

### 逻辑与运算符

``````a = 5
b = 10
c = a > 0 and b > 0
print(c)  # 输出：True
``````

### 逻辑或运算符

``````a = 5
b = 10
c = a > 0 or b > 0
print(c)  # 输出：True
``````

TA 点赞

0

8

• 推荐
• 评论
• 收藏
• 共同学习，写下你的评论

100积分直接送

0/150