打赏

python运算符

python运算符

1.数学运算符

常见+,-,*,/,%,//(地板除),**

print(10 + 20)
print(10/4) # 2
print(10//4)  # 向上取整 3
print(2 ** 3) #2的三次方
-------------------------
number = 10
number = number + 1
print(number)
------------------------
number2 = 10
number2 += 1   # number += 1  ==> number = number +1
print(number2)

2.比较运算符

常见:>,>=,<,<=,==

number1 = 10
number2 = 20
print(number1 > number2)

3.逻辑运算符

and 并且 or 或者 not 取反

score = 70
print(score > 70 and score < 80)
print(score > 70 or score <10)
print(not score > 70)

4.数字相关的模块

(1.)math模块

import math
print(math.sqrt(9))
print(math.log10(100))

(2.)生成随机数 random

import random
print(random.random())
print(random.randint(5,100)) #随机生成5-100的整数
posted @ 2021-10-17 23:05  苍山落暮  阅读(157)  评论(0编辑  收藏  举报