Python built-in functions--repr & STR
Repr & Str
Repr (object) & Str (object)
Repr (object) returns a printable string representing the object.
This is consistent with the results that are processed by conversion (anti-quote ").
as a normal function, you can use this operation at some point as useful.
For most types, this function attempts to return a string that, when passed to Eval (), produces the same object,
(that is, eval (repr (object) ==object.) Otherwise, a string surrounded by angle brackets is generated,
Contains additional information such as the object type name and usually some object names, as well as object addresses.
A class can control the return value of its own instance about the function by redefining the __repr__ () member function.
Str (object) returns a printable, friendly string representing the object.
for a string, it returns itself. The difference between
and Repr (object) is that str (object) does not attempt to return a string passed to Eval ();
Its goal is to return a printable string.
If no arguments are given, returns an empty string (the same to the class, which can be controlled by the __str__ () member)
>>> print repr ("Hello world!") ' Hello world! ' >>> print repr (10000L) 10000l>>> print str ("Hello world!") Hello world!>>> print str (10000L) 10000>>> temp = 42>>> print "The temperature is" +temptraceba CK (most recent): File "<pyshell#18>", line 1, in <module> print "The temperature is" +tempt Ypeerror:cannot concatenate ' str ' and ' int ' objects>>> print "The temperature is" + ' temp ', the temperature is 42& gt;>> print "The temperature is" + repr (temp), the temperature is 42
Above is the Python built-in function--repr & str content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!