What are some common casting commands?

int(<value to be cast>)
float(<value to be cast>)
str(<value to be cast>)
tuple(<value to be cast>)
list(<value to be cast>)
#examples

#cast string to integer
>>> int("12345")
12345

>>> int("12345.1")
12345

#cast string to float
>>> float("123.12")
123.12

#cast integer to string
>>> str(12345)
'12345'

#cash list to tuple
>>> tuple([1,2,3])
(1, 2, 3)

#cast tuple to list
>>> list((1,2,3))
[1, 2, 3] 
Advertisements