Converting Python Objects Into String


str() is used to convert python objects into string.

Syntax :
 
str(<python_object>)
Example :
 
S1="inspire"
a=str(S1)
print(a, type(a))

S2=[10,20,30]
b=str(S2)
print(b, type(b))

S3={"A":10, "b":20}
c=str(S3)
print(c, type(c))

S4=12
d=str(S4)
print(d, type(d))

S5=True
e=str(S5)
print(e, type(e))

S6=12.5
f=str(S6)
print(f, type(f))
Output :
 
inspire <class 'str'>
[10, 20, 30] <class 'str'>
{'A': 10, 'b': 20} <class 'str'>
12 <class 'str'>
True <class 'str'>
12.5 <class 'str'>