Python str() Function

Example

Convert the number 3.5 to a string:

x = str(3.14)

Run Instance

Definition and Usage

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

Syntax

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

Parameter Value

Parameter Description
object Any object. Specify the object to be converted to a string.
encoding The encoding of the object. The default is UTF-8.
errors Specify what to do when decoding fails.

More Examples

Example

Convert a string to an integer:

x = int("15")

Run Instance