In Python2.7, we have one way to print a formatted string:
print '%s has %d books and %f$' % ('Bob', 5, 2.21)
The %s
%d
%f
is very like printf
in C.
Is there an opposite operation to read a formatted string into variable,
just like scanf
in C ?
For example, I want to assign a = 'Bob', b = 5, c = 2.21 with two string:
"Bob has 5 books and 2.21$" and "%s has %d books and %f$"
How can I implement this function ?