Python
-
2. 숫자 계산하기Python/Grammar 2022. 11. 28. 12:52
# 정수 계산하기 사칙연산하기: + - * / >>> 10 + 1 11 >>> 10 / 2 5.0 # 파이썬3은 몫으로 완전히 나누어떨어져도 5.0과 같이 실수가 나옴 버림 나눗셈 몫 구하기: // >>> 7 // 3 2 >>> 6 // 3 2 나눗셈 나머지 구하기: % >>> 3 % 1 0 거듭제곱 구하기: ** >>> 3 ** 3 27 값을 정수로 만들기 : integer(정수)를 의미하는 int를 사용한다. int(숫자) int(계산식) int(문자열) >>> int('500') 500 객체의 자료형 알아내기 type(값) >>> type(500) 몫과 나머지 함께 구하기 : divmod를 사용해 피제수를 제수로 나누면 튜플 형태로 몫과 나머지가 반환된다. divmod(피제수, 제수) -> (몫, ..