Finance를 위한 Python 입문
Adina Howe
Professor
| 변수 유형 | 예시 |
|---|---|
| 문자열 | 'hello world' |
| 정수 | 40 |
| 실수 | 3.1417 |
| 불리언 | True 또는 False |
| 변수 유형 | 예시 | 약어 |
|---|---|---|
| 문자열 | 'Tuesday' | str |
| 정수 | 40 | int |
| 실수 | 3.1417 | float |
| 불리언 | True 또는 False | bool |
유형을 확인하려면 type() 함수를 사용합니다:
type(variable_name)
pe_ratio = 40
print(type(pe_ratio))
<class 'int'>
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
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 입문