Convert from one type to another with the:
methods:
convert from int to float:
x = 1 # int y = 2.8 # float z = 1j # complex
a = float(x)
convert from float to int:
b = int(y)
convert from int to complex:
c = complex(x)
convert 1 to a float
float(1)
1.0
convert 1.3 to an int
int(1.3)
1
Rember int will not round up
Everything in Python can be truend into what?
Booleon
bool
>>> bool(1)
True
bool of 0 will return:
false
>>> bool(0)
False
>>>>bool(0.0)
False
If there is 0 lenth string
bool(‘ ‘)
false