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