.format() Flashcards
> > > pi = 3.141596
‘pi = {___}’.format(pi)
3.141596
> > > pi = 3.141596
‘pi = {}’.format(pi)
3.141596
> > > pi = 3.141596
‘pi = {___}’.format(pi)
3.14
> > > pi = 3.141596
‘pi = {:2f}’.format(pi)
3.14
> > > pi = 3.141596
‘pi = {___}’.format(pi)
***3.141596
> > > pi = 3.141596
‘pi = {:>11}’.format(pi)
**3.141596
> > > pi = 3.141596
‘pi = {___}’.format(pi)
3.141596***
> > > pi = 3.141596
|»_space;> ‘pi = {:*
> > > pi = 3.141596
‘pi = {___}’.format(pi)
3.141596
> > > pi = 3.141596
‘pi = {:*^12}’.format(pi)
3.141596
> > > pi = 3.141596
‘pi = {:*^11}’.format(pi)
*3.141596**
> > > pi = 3.141596
‘pi = {:*^11}’.format(pi)
*3.141596**
> > > pi = 3.141596
‘pi = {___}’.format(pi)
3.141596 (9 spaces)
> > > pi = 3.141596
‘pi = {:17}’.format(pi)
3.141596
What does ‘{s}’.format(x) do?
Inserts string ‘x’ at {s}
What does ‘{c}’.format(x) do?
Inserts unicode character ‘x’ at {c}, where ‘c’ is an integer
What does ‘{b}’.format(x) do?
Inserts binary number ‘x’ at {b}, where ‘b’ is an integer
What does ‘{d}’.format(x) do?
Inserts decimal integer ‘x’ at {d}