Python str() Function

❮ Built-in Functions


Example

Convert the number 3.5 into an string:

x = str(3.5)
Try it Yourself »

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")
Try it Yourself »

❮ Built-in Functions

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.