-
-
The str() function is meant to return representations of
values which are fairly human-readable, while repr() is
meant to generate representations which can be read by the interpreter
(or will force a SyntaxError if there is not equivalent
syntax). -
print repr(x).rjust(2), repr(x*x).rjust(3),
… # Note trailing comma on previous line
… print repr(x*x*x).rjust(4) -
>>> for x in range(1,11):
… print ‘%2d %3d %4d’ % (x, x*x, x*x*x) -
mode can be
'r'when
the file will only be read,'w'for only writing (an existing
file with the same name will be erased), and'a'opens the file
for appending; any data written to the file is automatically added to
the end.'r+'opens the file for both reading and writing.
The mode argument is optional;'r'will be assumed if
it’s omitted. -
Python provides a standard module called
pickle. This is an
amazing module that can take almost
any Python object (even some forms of Python code!), and convert it to
a string representation; this process is called pickling.
-