Home / Python / Reference / Built-in functions

Python str() function

Convert a value to its text form.

Syntax

str(obj="")

Every value can be turned into a string. Needed when joining numbers to text with +; f-strings do the conversion for you.

Parameters

objany value

Return value

str

Example

Code

age = 30
print("Age: " + str(age))
print(str(3.14), str(True), str([1, 2]))
print(f"Age: {age}")          # usually simpler
print(len(str(2 ** 100)), "digits")

Output

Age: 30
3.14 True [1, 2]
Age: 30
31 digits

Related

Learn it step by step in the free lesson Values, Variables & Numbers, with exercises that check your answers.