str(object='')
str(object=b'', encoding='utf-8', errors='strict')
String representation of an object.
Parameters
The str() function takes three parameters:
object- the object whose string representation is returnedencoding- used to decode the given bytes object (e.g., UTF-8, ASCII)errors- specifies the response when decoding fails (e.g., strict, ignore, replace)
Return Value
The str() function returns:
- a printable string representation of the object
- a string representation of the bytes object in the specified encoding
Examples
# String representation
name = str('Nick')
print(name)
# String representation of an integer
age = str(24)
print(age)
# String representation of a numeric string
height = str('175cm')
print(height)
# Result
Nick
24
175cm