728x90
Python에서 사용하는 연산자들의 정리입니다.
산술 연산자
| 연산자 표현 | 뜻 | 사용법 |
| + | 더하기 | a = 1 + 2 |
| - | 빼기 | a = 1 - 2 |
| * | 곱하기 | a = 2 * 3 |
| / | 나누기 | a = 3 / 2 |
| // | 몫 | a = 3 // 2 |
| % | 나머지 | a = 3 % 2 |
| ** | 거듭제곱 | a = 2 ** 3 |
관계 논리 연산자
| 연산자 표현 | 뜻 |
| > | 작다 |
| < | 크다 |
| <= | 크거나 같다 |
| >= | 작거나 같다 |
| == | 같다 |
| != | 같지 않다 |
| and | 논리 and |
| or | 논리 or |
| not | 논리 not |
비트 연산자
| 연산자 | 뜻 |
| & | bit and |
| | | bit or |
| ^ | bit exclusive or |
| << | shift left |
| >> | shift right |
구성원 및 식별 연산자
| 연산자 | 뜻 | 사용법 |
| in | 구성원에 있다 | a = "abc def ghi" b = [1, 2, 3, 4] c = {'a':'aaa', 'b':'bbb'} print("abc" in a) print("cde" in a) print(2 in b) print(7 in b) print ('a' in c) print ('c' in c) |
| not in | 구성원에 없다 | a = "abc def ghi" b = [1, 2, 3, 4] c = {'a':'aaa', 'b':'bbb'} print("abc" not in a) print("cde" not in a) print(2 not in b) print(7 not in b) print ('a' not in c) print ('c' not in c) |
| is | 같다 | a = 10 b = 10 c = a d = 100 print(a is b) print(a is c) print(a is d) print(id(a), id(b), id(c), id(d)) x = [1, 2, 3, 4] y = x print(x is y) y[0] = 7 print(x is y) #x와 y가 같은 객체가 되기 때문에 y[0] 변경이 x[0]에도 반영됨 |
| is not | 다르다 | x = [1, 2, 3, 4] z = [1, 2, 3, 4] print(x is not z) #들어있는 값이 같아도 객체가 다른 주소값을 가짐 a = [1, 2, 3, 4] #shallow copy (a와 b가 같음) b = a #deep copy (a와 c가 다름) c = a.copy() print(a is b) print(a is c) b[0] = 2 c[0] = 3 print(a) print(b) print(c) |
'프로그래밍 언어 > Python' 카테고리의 다른 글
| Python 함수 (function) -def- (0) | 2021.02.27 |
|---|---|
| Python 반복문 (for, while) (0) | 2021.02.27 |
| Python의 조건 판단 (if-elif-else) (0) | 2021.02.26 |
| Python의 Data type (파이썬 데이터 타입) (0) | 2021.02.26 |
| Python 환경설정 -Python 3.9, PyCharm 설치- (0) | 2021.02.26 |