반응형
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding:utf-8 -*- | |
#test by Xd | |
x = 0 #x에 0을 대입 | |
print(x) #x의 값을 출력 | |
x += 2 #x = x + 2, 축약해서 x += 2 | |
print(x) #x의 값을 출력 | |
x -= 3 #x = x - 3, 축약해서 x -= 3 | |
print(x) #x의 값을 출력 | |
x *= 4 #x = x * 4, 축약해서 x *= 4 | |
print(x) #x의 값을 출력 | |
x /= 2 #x = x / 2, 축약해서 x /= 2 | |
print(x) #x의 값을 출력 |

어떤 변수와 값을 연산한 결과를 다시 동일한 변수에 대입할 때, 연산자 축약으로 표현할 수 있다.
x = x + 2 와
x += 2 의 결과는 같다.
덧셈만이 아닌 다른 사칙연산들도 전부 축약하여 표현할 수 있다.
-는 -=,
*는 *=,
/는 /= 등으로 축약한다.
반응형
'homework-jueon > 0x01-200제' 카테고리의 다른 글
24. 논리 연산자 (0) | 2020.01.02 |
---|---|
23. 관계 연산자 (0) | 2020.01.02 |
20. 사칙 연산자( + , - , * , / , ** ) (0) | 2020.01.01 |
19. 대입 연산자(=) (0) | 2020.01.01 |
18. 복소수형 자료 (0) | 2020.01.01 |