산술연산
| 연산자 |
설명 |
| + |
더하기 |
| – |
빼기 |
| * |
곱하기 |
| / |
나누기 |
| // |
몫 |
| % |
나머지 |
| ** |
제곱 |
x = 5
y = 2
print(x+y)
# 7
print(x-y)
# 3
print(x*y)
# 10
print(x/y)
# 2.5
print(x//y) # 몫
# 2
print(x%y) # 나머지
# 1
print(x**y) # 제곱
# 25
문자열연산
a = "hello"
b = "python"
c = "world"
word = a+b+c
print(word)
# hellopythonworld
print(a, b, c)
# hello python world
multi_word = (word+"\n") * 5
print(multi_word, end="")
"""
hellopythonworld
hellopythonworld
hellopythonworld
hellopythonworld
hellopythonworld
"""
복합할당연산
level = 10
level += 1 # 11
level -= 2 # 9
level *= 4 # 36
level /= 2 # 18.0
비교연산
| 연산자 (연산기호) |
설명 (왼쪽이 오른쪽보다) |
| > |
크다 |
| < |
작다 |
| >= |
크거나 같다 |
| <= |
작거나 같다 |
| == |
같다 |
| != |
다르다 |
print(1>2)
# False
print(3<4)
# True
print(5>=5)
# True
print(6<=7)
# True
print("팔" == "구")
# False
print("19285028583986982" != "19285028563986982")
# True
논리연산
| 연산자 |
설명 |
| A and B |
A,B 모두 참이라면 True |
| A or B |
A,B 중 하나라도 참이라면 True |
| not A |
A 가 참이라면 False |
print(1<2 and 3>4)
# False
print(5<=6 or 7>=8)
# True
print(not 9==9)
# False
멤버십연산
| 연산자 (연산기호) |
설명 (왼쪽이 오른쪽에)
|
| in |
포함되어 있다 |
| not in |
포함되어 있지 않다 |
print("3" in "123")
# True
print("3" not in "123")
# False