4 - Type Casting

What is Type Casting?

Type casting is the process of converting one data type to another data type.

Info

Type Casting is also known as Type converting.

In Python, we can convert one data type to another data type using the following functions:

str() - converts any data type into a string type
int() - converts any data type into integer type
float() - converts any data type into float type
tuple() - This function is used to convert to a tuple.
dict() - This function is used to convert a tuple of order (key, value) into a dictionary.
list() - This function is used to convert any data type to a list type.
set() - This function returns the type after converting to set.

ord() - converts characters into ASCII code
hex() - converts integers to hexadecima
oct() - converts integer to octal
complex() - This function converts real numbers to complex(real, imag) number.
bool() - This function converts any data type to Boolean data type.
chr( )- converts ASCII code to its corresponding character
bin() - converts integer to binary string
bytearray() - returns array of given byte size
memoryview() - returns memory view object