Variabele datatypes

Introductie tot Python voor Finance

Adina Howe

Instructor

Python-datatypes

Variabeletype Voorbeeld
Strings 'hello world'
Integers 40
Floats 3.1417
Booleans True of False
Introductie tot Python voor Finance

Variabeletype

Variabeletype Voorbeeld Afkorting
Strings 'Tuesday' str
Integers 40 int
Floats 3.1417 float
Booleans True of False bool
Introductie tot Python voor Finance

Welk datatype heeft een variabele: type()

Om het type te zien, gebruik je de functie type():

type(variable_name)
pe_ratio = 40
print(type(pe_ratio))
<class 'int'>
Introductie tot Python voor Finance

Variabelen bewerken

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
Introductie tot Python voor Finance

Variabeletype wijzigen

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!
Introductie tot Python voor Finance

Laten we oefenen!

Introductie tot Python voor Finance

Preparing Video For Download...