miscellaneous topics ii string formatting suppose we are writing program that calculates tip on bill of $ when we multiplywe get but we would like to display the result as $ not $ here is how to do ita print'the tip is { fformat( )this uses the format method of strings here is another examplebill tip print'tip${ }total${ fformat(tipbill+tip)the way the format method works is we put pair of curly braces {anywhere that we want formatted value the arguments to the format function are the values we want formattedwith the first argument matching up with the first set of bracesthe second argument with the second set of bracesetc inside each set of curly braces you can specify formatting code to determine how the corresponding argument will be formatted formatting integers to format integersthe formatting code is {:dputting number in front of the allows us to right-justify integers here is an exampleprint'{: dformat( )print'{: dformat( )print'{: dformat( ) the number in these examples says that the value is allotted three spots the value is placed as far right in those three spots as possible and the rest of the slots will be filled by spaces this sort of thing is useful for nicely formatting tables to center integers instead of right-justifyinguse the characterand to left-justifyuse the character print'{:^ dformat( )print'{:^ dformat( )print'{:^ dformat( ) each of these allots five spaces for the integer and centers it within those five spaces putting comma into the formatting code will format the integer with commas the example below prints , , print'{:,dformat( )