변수 데이터 유형

Finance를 위한 Python 입문

Adina Howe

Professor

Python 데이터 유형

변수 유형 예시
문자열 'hello world'
정수 40
실수 3.1417
불리언 True 또는 False
Finance를 위한 Python 입문

변수 유형

변수 유형 예시 약어
문자열 'Tuesday' str
정수 40 int
실수 3.1417 float
불리언 True 또는 False bool
Finance를 위한 Python 입문

변수의 데이터 유형: type()

유형을 확인하려면 type() 함수를 사용합니다:

type(variable_name)
pe_ratio = 40
print(type(pe_ratio))
<class 'int'>
Finance를 위한 Python 입문

변수 조작

x = 5
print(x * 3)
15
print(x + 3)
8
y = 'stock'
print(y * 3)
'stockstockstock'
print(y + 3)
TypeError: must be str, not int
Finance를 위한 Python 입문

변수 유형 변경

pi = 3.14159
print(type(pi))
<class 'float'>
pi_string = str(pi)
print(type(pi_string))
<class 'str'>
print('I love to eat ' + pi_string + '!')
I love to eat 3.14159!
Finance를 위한 Python 입문

연습해 봅시다!

Finance를 위한 Python 입문

Preparing Video For Download...