Python Tipe Omskakeling
Tik Omskakeling
Jy kan van een tipe na 'n ander omskakel met die int()
,
float()
, en complex()
metodes:
Voorbeeld
Skakel van een tipe na 'n ander:
x = 1 # int
y = 2.8 # float
z = 1j # complex
#convert from int to float:
a = float(x)
#convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
Let wel: Jy kan nie komplekse getalle na 'n ander getaltipe omskakel nie.