w3resource

Python: str() function

str() function

The str() function is used to convert the specified value into a string.

Version

(Python 3.2.5)

Syntax:

str(object='')
str(object=b'', encoding='utf-8', errors='strict')

Parameter:

Name Description
object Any object.
encoding

The encoding of the given object. Default is UTF-8.

errors

Specifies what to do if the decoding fails.

Return value:

A string.

Example: Python str() function

print(str(15))

Output:

15

Example: Python str() function

# bytes
x = bytes('cöde', encoding='utf-8')

print(str(x, encoding='ascii', errors='ignore'))

Output:

cde

Pictorial Presentation:

Python: Built-in-function - str() function

Python Code Editor:

Previous: sorted()
Next: sum()

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python/built-in-function/str.php