Generic Syntax "text {} text {} text {}." .format(var1, var2, var3) Can use index numbers Place width and precision in curly brackets ({}). Index Numbers #Demonstration of use of index numbers in .format() method atom1, atom2, atom3 = "Hydrogen", "Helium", "Lithium" print("This string has order first, second, third variable {} {} {}."\ .format(atom1,atom2,atom3)) print("This string has order third variable {2}, second variable {1} "\ "first variable {0}.".format(atom1, atom2, atom3)) print("This string has order first variable {0}, second variable {1} "\ "first variable {0}.".format(atom1, atom2, atom3)) Hello world! Exercise \(\PageIndex{1}\) What value do index numbers in Python start with (what is the index number of the first variable? Answer 0, atom one is the first variable and has an index number of zero. Width and Precision Analyze the following code, predict the output and run. If it is different than predicted, be sure to understand why. Note; we are using the pipe symbol (|) to indicate the divider between two columns in our data output. The first column is the names of elements are they are string variables, and the second are their molar masses, and they are floats #Demonstration of use of width and precisioin of .format() method print("{0:10}|{1:10}\n{2:10}|{3:10}\n1234567890|1234567890"\ .format("hydrogen",1.00784, "helium", 4.002602)) print(10*" * ") print("{0:10}|{1:10.3f}\n{2:10}|{3:10.3f}".format("hydrogen",1.00784, "helium", 4.002602)) Hello world! Exercise \(\PageIndex{2}\) Adjust the code above so the print output of the atomic masses below the row of stars show a precision of 4 decimal places Answer print("{0:10}|{1:10.4f}\n{2:10}|{3:10.4f}".format("hydrogen",1.00784, "helium", 4.002602)) Aligning columns Run and analyze the following code to figure out the syntax to left align, right align and center align data in a columns. #left aligned spaced at 15 digits print("{0:<15}|{0:<15}".format("left align", "center align", "right align")) #left then right aligned spaced at 15 digits print("{0:<15}|{2:>15}".format("left align", "center align", "right align")) #center aligned spaced at 15 digits print("{1:^15}|{1:^15}".format("left align", "center align", "right align")) Hello world!