THE WORLD'S LARGEST WEB DEVELOPER SITE

Python str() Function

❮ Built-in Functions


Example

Convert the number 3.5 into an string:

x = str(3.5)
Run example »

Definition and Usage

The str() function converts the specified value into a string.


Syntax

str(object, encoding=encoding, errors=errors)

Parameter Values

Parameter Description
object Any object. Specifies the object to convert into a string
encoding The encoding of the object. Default is UTF-8
errors Specifies what to do if the decoding fails

More Examples

Example

Convert a string into an integer:

x = int("12")
Run example »

❮ Built-in Functions