June 2002
Beginner to intermediate
640 pages
14h 24m
English
Although not actually modulus, the Python % operator works similarly in string formatting to interpolate variables into a formatting string. If you've programmed in C, you'll notice that % is much like C's printf(), sprintf(), and fprintf() functions.
There are two forms of %, one of which works with strings and tuples, the other with dictionaries.
StringOperand % TupleOperand StringOperand % DictionaryOperand
Both return a new formatted string quickly and easily.
In the StringOperand % TupleOperand form, StringOperand represents special directives within the string that help format the tuple. One such directive is %s, which sets up the format string
>>> format = "%s is my friend and %s ...
Read now
Unlock full access