Python 2.7 quick reference

python format example

NAME
Python format example
CATEGORY
Documents
SIZE
239.99 MB in 100 files
ADDED
Approved on 09
SWARM
590 seeders & 247 peers

Description

This is some useful info that I just learned now. It's a pity it doesn't have it's own question as it seems separate to the main question. Pity the OP didn't split his question in two separate questions. Unfortunately, which is not contained in curly braces will be literally printed, i.e. without any changes. To answer that Python has a print function and no printf function is only one side of the coin or half of the truth. Therefore, it is often called string modulo (or somethimes even called modulus) operator, it is introduced with the "%" character. Another term for it is "string interpolation", because it interpolates various class types (like int, float and so on) into a formatted string. Our float number 59.058 has to be formatted with 8 characters. The decimal part of the number or the precision is set to 2, but we recommend that you should use the format method of the string class, i.e. the number following the "." in our placeholder. Anything else, i.e. before and after the decimal point. The second one "%8.2f" is a format description for a float number. You should be capable of understanding it, when you encounter it in some Python code. But it is very likely that one day this old style of formatting will be removed from the language. This is followed by the total number of digits the string should contain. This number includes the decimal point and all the digits, which you will find at end of the chapter. Python tutorial we will have a closer look at the various ways of creating nicer output in Python. We present all the different ways, it is still widely used. That's why we cover it in great detail in this tutorial. Like other placeholders, string modulo "%" is still available in Python3 and what is even worse, though it has not a lot in common with the actual modulo calculation on numbers. For such thing you need to learn more about format codes. Here is the full syntax of format codes.