Python开发第二篇运算符

Posted Tanglaoer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python开发第二篇运算符相关的知识,希望对你有一定的参考价值。

"+" 加号

__author__ = Tang

a = 8
b = 9
c = a + b
print(c)  # 17

a = 8.0
b = 9
c = a + b
print(c)  # 17.0

a = 8
b = 9.0
c = a + b
print(c)  # 17.0

“-” 减号

__author__ = Tang

# 正数
a = 9
b = 8
c = a - b
print(c)  # 1

a = 9.0
b = 8
c = a - b
print(c)  # 1.0

a = 9
b = 8.0
c = a - b
print(c)  # 1.0

# 负数
a = 8
b = 9
c = a - b
print(c)  # -1

a = 8.0
b = 9
c = a - b
print(c)  # -1.0

a = 8
b = 9.0
c = a - b
print(c)  # -1.0

"*" 乘号

__author__ = Tang

a = 9
b = 8
c = a * b
print(c)  # 72

a = 9.0
b = 8
c = a * b
print(c)  # 72.0

a = 9
b = 8.0
c = a * b
print(c)  # 72.0

"/" 除号

__author__ = Tang

a = 9
b = 3
c = a / b
print(c) # 3.0

a = 9.0
b = 3
c = a / b
print(c) # 3.0

a = 9
b = 3.0
c = a / b
print(c) # 3.0

a = 9
b = 8
c = a / b
print(c)  # 1.125

a = 9.0
b = 8
c = a / b
print(c)  # 1.125

a = 9
b = 8.0
c = a / b
print(c)  # 1.125

 

"%" 求余


__author__ = ‘Tang‘

a = 9
b = 3
c = a % b
print(c) # 0

a = 9.0
b = 3
c = a % b
print(c) # 0.0

a = 9
b = 3.0
c = a % b
print(c) # 0.0

a = 9
b = 8
c = a % b
print(c) # 1

a = 9.0
b = 8
c = a % b
print(c) # 1.0

a = 9
b = 8.0
c = a % b
print(c) # 1.0

"**" 次方

__author__ = Tang

a = 9
b = 3
c = a ** b
print(c) # 729

a = 9.0
b = 3
c = a ** b
print(c) # 729.0

a = 9
b = 3.0
c = a ** b
print(c) # 729.0

"//" 取整

__author__ = Tang

a = 9
b = 3
c = a // b
print(c) # 3

a = 9.0
b = 3
c = a // b
print(c) # 3.0

a = 9
b = 3.0
c = a // b
print(c) # 3.0

a = 5
b = 2
c = a // b
print(c) # 2

a = 5.0
b = 2
c = a // b
print(c) # 2.0

a = 5
b = 2.0
c = a // b
print(c) # 2.0

 

以上是关于Python开发第二篇运算符的主要内容,如果未能解决你的问题,请参考以下文章

Python开发第二篇:Python基本数据类型

Python开发第二篇:Python基本数据类型

Python开发第二篇:运算符比较关系运算符

python基础篇第二篇

python学习第二篇

python笔记 [第二篇]:基础数据类型