The str() function is used to convert an object into its  string representation. It can also be used without any argument to create an empty string.

Syntax:
str() #create an empty string
str(object) #get the string representation of the given object.

When the function is called without an argument, it simply returns an empty string.

ExampleEdit & Run
S = str()
print(S)
Output:
[Finished in 0.010445695137605071s]

When the function is called with an argument, it returns the string representation of the object.  Any given object in Python possesses a string representation , rendering all objects as valid arguments to the str() function.

ExampleEdit & Run
S = str(7)
print( S )

S = str([1, 2, 3, 5])
print( S )

S = str(('Python', 'Java', 'C++'))
print( S )

S = str({1:'one', 2:'two'})
print( S )

S = str(print)
print( S )

S = str(str)
print( S )


import math
print( str(math) )
Output:
7[1, 2, 3, 5]('Python', 'Java', 'C++'){1: 'one', 2: 'two'}<built-in function print><class 'str'><module 'math' from '/app/.heroku/python/lib/python3.11/lib-dynload/math.cpython-311-x86_64-linux-gnu.so'>[Finished in 0.010194814065471292s]

A user defined object can override its default string representation by defining the __str__() method.

ExampleEdit & Run
class MyObject():
   pass

x =MyObject()
print( str(x) )


class MyObject2():
    def __str__(self):
        return "A simple object."

y = MyObject2() 
print( str(y) )
Output:
<__main__.MyObject object at 0x7faa3019e610>A simple object.[Finished in 0.009470105171203613s]