In this article, we are going to learn all about the Python str() function to returns a string object.
If you want to convert any object into a string, Then it will be the best function to convert any object into a string.
Python str function
Python string is a built-in function that is used to convert any object into a string. str function in Python converted string.
The syntax of the str() function in Python.
str(object, encoding=encoding, errors=errors)
str function in Python accepts three parameters.
- object:- Required. Object to be converted into a string.
- encoding:- The encoding of the object.
- errors:- Specifies what to do if the decoding fails.
Python str function examples
Here we will take some examples to understand str function in Python.
x = 12.21 print(type(x)) result = str(x) print(type(result))
<class 'float'> <class 'str'>
x = [1,2,3,4,5] for i in x: print(str(i))
1 2 3 4 5
In this article, you have learned all about the Python str function to convert any object into a string. In previous tutorials, we have learned all about Python built-in functions along with examples.
If you like this article, please share and keep visiting for further Python tutorials.
Python built-in functions
For more information:- Click Here