What is the difference between the different %(insert letter here)


What are the differences between the %(Insert letter here). And what are all of them and what do they do. A list would be appreciated. Thank you : )

For example:
%s = Im not exactly sure
%d = no clue
Those are the only ones I know



The % symbol, when used in string formatting, allows a shorthand way to display string and non-string types within a single print statement. The benefit of using string formatting operations is that you don't have to use any str() conversions or concatenation to achieve a correctly formatted string output.

The usage follows:

print "Here are %i examples of string formatting: %f is a floating point decimal. %u is an unsigned integer decimal. %d is a signed integer decimal, just like %i" % (4, 5.22, 12, -4, 7)


Here are 4 examples of string formatting: 5.22 is a floating point decimal. 12 is an unsigned integer decimal. -4 is a signed integer decimal, just like 7.

Inside the print statement, the % operator acts as a placeholder for actual values. The type designation must be chosen carefully to retain the accuracy of the value you want to print.

After the print statement is closed with an end-quote, we place a % symbol and then a n-tuple follows, containing the values in order that we want to display. The values must be in the order you intend and correspond to the correct types in the print statement, or you might get values you aren't expecting.

Here is a full list of the type designations you are most likely to ever need:

And here are some additional link on strings and string formatting:



Hope this helps!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.