Type Conversion in Python
In this articles, we will look to Type Conversion in Python.
In earlier article, we saw the dictionary type variables in Python. We recall earlier part that dictionaries are a compound type variable similar to C, C++ and C# arrays but can store different type of variables like int, string and others. Python dictionaries contain values like key-pairs. A dictionary key can be any Python type. Mainly numbers or string s. Value can be any arbitrary Python object.
In this part, we will see how to convert data types into each in Python.
Python data type conversation code example:
#!/usr/bin/python
x= 1
y = "2"
#to int
print(int(y)+x)
Lets see Type Conversion in a Python example.
In above example, we converted a string data type into integer in Python, print it to terminal.