반응형
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 = 2 #x에 2 대입 | |
y = 4 #y에 4 대입 | |
cal1 = x + y | |
print(cal1) | |
cal2 = x - y | |
print(cal2) | |
cal3 = x * y | |
print(cal3) | |
cal4 = x / y | |
print(cal4) | |
cal5 = x ** y #각종 대입과 출력 과정 | |
print(cal5) | |
cal6 = x + x * y / x | |
print(cal6) | |
cal7 = ( x + y ) * ( x - y ) | |
print(cal7) | |
cal8 = x * y ** x | |
print(cal8) |

파이썬에서 사칙연산은 수학에서의 사칙연산과 동일하다.
하지만 곱셈 기호와 나눗셈 기호는 수학에서 사용하는 것과 다른데,
파이썬에서는 곱셈은 (*)으로 쓰고 나눗셈은 (/)로 사용한다.
**은 거듭제곱을 나타내는 기호이고
2 ** 4 이면 2의 4제곱인 16을 나타낸다.
계산 순서 :
거듭제곱, 괄호 > 곱셈, 나눗셈 > 덧셈, 뺄셈 순서이다.
반응형
'homework-jueon > 0x01-200제' 카테고리의 다른 글
23. 관계 연산자 (0) | 2020.01.02 |
---|---|
21. 연산자 축약 (0) | 2020.01.02 |
19. 대입 연산자(=) (0) | 2020.01.01 |
18. 복소수형 자료 (0) | 2020.01.01 |
17. 실수형 자료 (0) | 2020.01.01 |