Python str() Function
Returns an object converted to a string.
Syntax
Python
Copy Code
str(object) str(buffer, encoding = sys.getdefaultencoding(), errors = "strict")
Parameters
Parameter | Description |
---|---|
object |
Required. The object to be converted to a string. |
buffer |
Required. The buffer to be converted to a string. |
encoding |
Optional. The name of the encoding used to decode the buffer. If
encoding is then the first parameter must be a data buffer.
Default is sys.getdefaultencoding()
|
errors |
Optional. The error handling method to use in case of errors. If
errors is supplied then the first parameter must be a data buffer.
Default is 'strict'.
Possible values are
|
Example
Python
Copy Code
aString = str(3.14) print(aString, ' is a string: ', type(aString) is type('string'))
Output
3.14 is a string: True