Pengantar Python untuk Keuangan
Adina Howe
Instructor
| Tipe Variabel | Contoh |
|---|---|
| String | 'hello world' |
| Integer | 40 |
| Float | 3.1417 |
| Boolean | True atau False |
| Tipe Variabel | Contoh | Singkatan |
|---|---|---|
| String | 'Tuesday' | str |
| Integer | 40 | int |
| Float | 3.1417 | float |
| Boolean | True atau False | bool |
Untuk mengetahui tipe, gunakan fungsi 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!
Pengantar Python untuk Keuangan