Pot: String formatting
Starting with Python 2.6 there is a new format function to do string formatting. I’ve always been a bit overwhelmed by the official Format String Syntax documentation so I’ll try to present it to you with more examples. Python so far had the ‘%’ operator. It’s been deprecated with Python 2.6 and removed from Python 3. Instead string has a new format method. >>> "This is an %s-style formatting" % "old" 'This is an old-style formatting' >>> "This is a {0}-style formatting".format("new") 'This is an new-style formatting' Formatting options go after a colon, for example the width specifications together with alignment options which are mostly useful for tabular representations. Let’s print the following table as an exercise: ...