Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python typecast

print(str(1))  # convert number to string
print(int("1"))  # convert string to int
print(float(1))  # convert int to float
print(list('hello'))  # convert string to list
print(tuple('hello'))  # convert string to tuple
print(list((1, 2, 3)))  # convert tuple to list
print(tuple([1, 2, 3]))  # convert list to tuple
print(bool(1))  # convert a number to boolean
print(bool(0))  # convert a number to boolean
print(bool(""))  # convert a string to boolean
print(bool("data"))  # convert string to boolean
print(bin(10))  # convert an integer to a binary string
print(hex(10))  # convert an integer to a hex string
print(oct(10))  # convert an integer to an octal string
Comment

typecasting python

a = "1235"
a = int(a)

print(type(a))
print(a + 5)
Comment

how to tyoecast in python

example = 1.3234325
print(type(example))




Comment

PREVIOUS NEXT
Code Example
Python :: python check if object is empty 
Python :: how to decrease size of graph in plt.scatter 
Python :: reportlab python add font style 
Python :: manage python environment in jupyterlab 
Python :: python generator expression 
Python :: python if true 
Python :: get coordinates of netcdf in python 
Python :: how to drop duplicate columns in pandas that dont have the same name? 
Python :: how to make a comment in python 
Python :: wifite2 
Python :: get key from dict python 
Python :: activate virtual environment 
Python :: django redirect 
Python :: pil format multiline text 
Python :: datetime.timedelta format to string python 
Python :: python lambda key sort 
Python :: python default keyword parameter list 
Python :: # enumerate 
Python :: python coding language 
Python :: get first element of tuple python 
Python :: tkinter simple application 
Python :: python os get dir path 
Python :: Normalize columns in pandas dataframe 
Python :: arrays python 
Python :: python pickle module 
Python :: shrink colorbar matplotlib 
Python :: python get class from string 
Python :: get first element of array python 
Python :: python how to raise an exception 
Python :: python module path 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =