码迷,mamicode.com
首页 > 编程语言 > 详细

Python开发【第二篇】运算符

时间:2018-08-12 15:32:43      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:pre   span   color   乘号   nbsp   bsp   auth   开发   class   

"+" 加号

__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开发【第二篇】运算符

标签:pre   span   color   乘号   nbsp   bsp   auth   开发   class   

原文地址:https://www.cnblogs.com/tangkaishou/p/9462775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!