Function Details: str

Description


Returns a string version of object.


Extended Description


The str() function returns a string representation of an object. If the object has a __str__() method, it calls that method to obtain the string representation. For strings, str() returns the string itself. When used with no arguments, it returns an empty string. If encoding and/or errors are given, str() is used to decode the object, which must be bytes or bytearray, into a string.


Read More about str from Python Documentation

Function Signature


str(object: Any = '', encoding: Optional[str] = None, errors: Optional[str] = 'strict') -> str

Module: builtins

Class: str

Parameters



Parameter List


  • object: Any
  • encoding: Optional[str]
  • errors: Optional[str]

Return


Returns a string representation of the given object.


Return Type


str

Output

Explanation

These examples show how str() works with different types of objects.