정수 123, -345, 0
실수 123.45, -1234.5, 3.4e10
8진수 0o34, 0o25
16진수 0x2A, 0xFF

정수형(integer)

>>> a = 123
>>> a
123
>>> type(a)
int

실수형(floating-point)

>>> a = 6.2
>>> a
6.2
>>> type(a)
float
# 실수형을 다음과 같이 컴퓨터식 지수 표현 방식(scientific notation)으로 표현가능
>>> a = 6.2e-23 # 6.2*10^-23를 의미
>>> a = 6.2E-23 # 위와 같음

복소수(complex)

>>> a = complex(1, 3)
>>> a
(1+3j)
>>> type(a)
complex
>>> a = 3-4j
>>> a
(3-4j)
>>> type(a)
complex

 


연산자

Operation Result
x + y sum of x and y
x - y difference of x and y
x * y product of x and y
x / y quotient of x and y
x // y floored quotient of x and y
x % y remainder of x / y
-x x negated
+x x unchanged
abs(x) absolute value or magnitude of x
int(x) x converted to integer
float(x) x converted to floating point
complex(re, im) a complex number with real part re, imaginary part im. im defaults to zero.
c.conjugate() conjugate of the complex number c
divmod(x, y) the pair (x // y, x % y)
pow(x, y) x to the power y
x ** y x to the power y

 

반응형

'Tech & Development > Programming Languages' 카테고리의 다른 글

[Python] 파일명, 디렉토리 경로 추출  (0) 2021.07.07
[Python] 자료형 - 문자열 (String)  (0) 2021.05.18
[ PyQt ] Button Widget  (0) 2021.01.31
[ PyQt ] Signal & Slot  (0) 2021.01.30
Python 패키지 설치  (0) 2021.01.29