1. 程式人生 > >python - 運算子

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)