th additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a repr() method.
class str(object='')
class str(object=b'', encoding='utf-8', errors='strict')
Return a string version of object. If object is not provided, returns the empty string. Otherwise, the behavior of str() depends on whether encoding or errors is given, as follows.
object.__repr__(self)
由repr()内建函数和调用以计算一个对象的“正式”的字符串表示。如果可能的话,这应该看起来像一个有效的Python表达式,可用于重新创建具有相同值的对象(给定适当的环境)。如果不可能,应该返回<...some useful description...>形式的字符串。返回值必须是一个字符串对象。如果一个类定义了__repr__()但没有定义__str__(),那么在请求该类的实例的“非正式”的字符串表示时也将调用__repr__()。
object.__str__(self)
由str(object)、内建函数format()和print()语句调用,以计算一个对象的“非正式的”或可打印的字符串表示。返回值必须是一个字符串对象。
与object.__repr__()不同的是,str()不需要返回一个合法的Python表达式:可以使用更合适或者精确的表示。
内建类型object默认的实现是调用object.__repr__()。
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Print objects to the text stream file, separated by sep and followed by end. sep, end, file and flush, if present, must be given as keyword arguments.
All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.
The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Since printed arguments are converted to text strings, print() cannot be used with binary mode file objects. For these, use file.write(...) instead.
Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.