operators and expressions $var symbols in stringsfor exampleif you have dictionary of valuesyou can expand those values into fields within formatted string as followsstock 'name'goog''shares 'price "%(shares) of %(name) at %(price) fstock " shares of goog at the following code shows how to expand the values of currently defined variables within string the vars(function returns dictionary containing all of the variables defined at the point at which vars(is called name "elwoodage "%(name) is %(age) years oldvars(advanced string formatting more advanced form of string formatting is available using the format(*args*kwargsmethod on strings this method collects an arbitrary collection of positional and keyword arguments and substitutes their values into placeholders embedded in placeholder of the form '{ }'where is numbergets replaced by positional argument supplied to format( placeholder of the form '{name}gets replaced by keyword argument name supplied to format use '{{to output single '{and '}}to output single '}for exampler "{ { { }format('goog', , "{name{shares{price}format(name='goog',shares= ,price= "hello { }your age is {age}format("elwood",age= "use {and }to output single curly bracesformat(with each placeholderyou can additionally perform both indexing and attribute lookups for examplein '{name[ ]}where is an integera sequence lookup is performed and in '{name[key]}where key is non-numeric stringa dictionary lookup of the form name['key'is performed in '{name attr}'an attribute lookup is performed here are some examplesstock 'name'goog''shares 'price "{ [name]{ [shares]{ [price]}format(stockx "{ real{ imag}format(xin these expansionsyou are only allowed to use names arbitrary expressionsmethod callsand other operations are not supported you can optionally specify format specifier that gives more precise control over the output this is supplied by adding an optional format specifier to each placeholder using colon (:)as in '{place:format_spec}by using this specifieryou can specify column widthsdecimal placesand alignment here is an exampler "{name: {shares: {price: }format (name="goog",shares= ,price= lib fl ff