Repr () function in Python, repr function in python
Python can convert any value into a string: Pass it into the repr () or str () function.
The str () function is used to convert a value into a form suitable for reading, while repr () is used as a form for the interpreter to read.
In the official API of python, the repr () function is interpreted as follows:
The string obtained by the repr () function can be used to obtain the object again. The input of repr () is friendly to python. In general, the equation obj = eval (repr (obj) is true.
>>> Obj = 'I love python' >>> obj = eval (repr (obj) True
The str () function does not have this function.
>>> Obj = eval (str (obj) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1 I love Python ^
Repr () function:
>>> Repr ([,]) '[,]' >>> repr ('hello ') "'hello'" >>> str (1.0/7.0) '0. 142857142857 '> repr (1.0/7.0)' 0. 14285714285714285'