Python uses C-style string formatting to create new, formatted strings. The "%" operator is used to format a set of variables enclosed in a "tuple" (a fixed size list), together with a format string, which contains normal text together with "argument specifiers", special symbols like "%s" and "%d".
Let's say you have a variable called "name" with your user name in it, and you would then like to print(out a greeting to that user.)
%s - String (or any object with a string representation, like numbers)
%d - Integers
%f - Floating point numbers
%.<number of digits>f - Floating point numbers with a fixed amount of digits to the right of the dot.
%x/%X - Integers in hex representation (lowercase/uppercase)
Exercise
You will need to write a format string which prints out the data using the following syntax:Hello John Doe. Your current balance is $53.44.
0 Comments