How to Construct a String From Various Data Types in Python


In this example, we will learn how to construct a string from a wide variety of data types in Python.

Source Code

a = str(6)     # a will be '6'
print(a)

b = str(6.6)   # b will be '6.6'
print(b)

c = str('6')   # c will be '6'
print(c)

d = str('Python 3')   # d will be 'Python 3'
print(d)

Output:

6
6.6
6
Python 3
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement