Skip to content

How to convert types of variablesin Python?

int(anyData) #any into integer
str(anyData) #any into string
ord(chr) #character into number
hex(int) #integer into hexadecimal string
oct(int) #integer into octal string
float(anyData) #any into float
tuple() #convert to tuple
set() #returns the type after converting to set
list() #convert any data type to a list
dict() #convert a tuple of order (key,value) into a dictionary
complex(real,imag) #converts real numbers to complex(real,imag) number
See also  Check if a day is weekday or weekend in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.