For objects which don’t have a particular
Which can be read by the interpreter (or will force a Synta圎rror if The str() function is meant to return representations of values which areįairly human-readable, while repr() is meant to generate representations Python has ways to convert any value to a string: pass it to the repr() One question remains, of course: how do you convert values to strings? Luckily, Yet another way to substitute values into strings. The string module contains a Template class which offers Way is to use formatted string literals, or the Strings to a given column width these will be discussed shortly. String type has some methods that perform useful operations for padding There are two ways to format your output theįirst way is to do all the string handling yourself using string slicing andĬoncatenation operations you can create any layout you can imagine.
Often you’ll want more control over the formatting of your output than simply See the Library Reference for more information on this.) Of file objects the standard output file can be referenced as sys.stdout. So far we’ve encountered two ways of writing values: expression statements and