type casting in python code example
Example 1: how to convert types of variablesin python
int(anyData)
str(anyData)
ord(chr)
hex(int)
oct(int)
float(anyData)
tuple()
set()
list()
dict()
complex(real,imag)
Example 2: python cast to float
float('1.234')
Example 3: typecasting inpython
>>> string = '123'
>>> type(string)
<class 'str'>
>>> integer = int(string)
>>> type(integer)
<class 'int'>
>>> float_number = float(integer)
>>> type(float_number)
<class 'float'>
>>> string, integer, float_number
('123', 123, 123.0)
Example 4: python type casting
var_as_num = 10
var_as_str = str(var_as_num)
Example 5: Python Casting
x = int(1)
y = int(2.8)
z = int("3")
Example 6: how to tyoecast in python
example = 1.3234325
print(type(example))