Python str() built-in function

From the Python 3 documentation

Return a string version of object. If object is not provided, returns the empty string. Otherwise, the behavior of str() depends on whether encoding or errors is given.

Introduction

The str() function in Python is a built-in function that returns a string version of an object. If no object is provided, it returns an empty string. It’s a versatile function for converting other data types to strings.

Examples

>>> # transform an integer to a string
>>> from_integer = str(29)
>>> from_integer
# '29'
>>> type(from_integer)
# <class 'str'>

>>> # transform a float to string
>>> from_float = str(-3.14)
>>> from_float
# '-3.14'
>>> type(from_float)
# <class 'str'>

>>> # return an empty string
>>> str()
# ''

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.