python - 运算符

#-*- coding:utf-8 -*-
# author:jiaxy
# datetime:2018/11/3 10:47
# software: PyCharm Community Edition

# 运算符


# 1. 算术运算符
# 加减乘除 + - * /
# 取模/取余 % 常用场景:判断奇偶数
a = 10
b = 3
c = a / b
d = a % b
print(c)
print(int(c))
print(d)


# 2. 赋值运算符
# = += -=
e = 5
print(e)
e += 5
print(e)
e -= 5
print(e)

# 3. 比较运算符
# == > < >= <= !=
# 比较运算结果为布尔值:True False

i = 10
j = 5
print(i > j)
print(i < j)

# 4. 逻辑运算符
# and or not 与或非
# and: 真真为真
# or : 假假为假
m = 5
n = -6
print(m > 0 and n > 0)
print(m > 0 or n < 0)

# 5. 成员运算符
# in0
# not in
s = 'elf'
print('e' in s)
print('e' not in s)

猜你喜欢

转载自www.cnblogs.com/gotesting/p/9900172.html