how to change any data type into a string in python


Question

How can I change any data type into a string in Python?

1
109
3/2/2016 2:42:08 PM

myvariable = 4
mystring = str(myvariable)  # '4'

also, alternatively try repr:

mystring = repr(myvariable) # '4'

This is called "conversion" in python, and is quite common.

101
7/8/2010 3:22:16 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon