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:
cdePictorial Presentation:
Python Code Editor:
Previous: sorted()
Next: sum()
Test your Python skills with w3resource's quiz
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://198.211.115.131/python/built-in-function/str.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics