Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> string = "code"
>>> z = 35
>>>
>>> print("My %s is %d lines long." % (string, z))
My code is 35 lines long.
>>>
>>> p = 3.141592
>>>
>>> print("Pi is about %f" % p)
Pi is about 3.141592
>>>
>>> print("Pi is about %.2f" % p)
Pi is about 3.14
>>>
>>> print("Pi is about %.4f" % p)
Pi is about 3.1416
>>>
>>>
>>> num_lst = [234.575742, 14.46574, 8.231235, 19.4239823928398]
>>>
>>> for num in num_lst:
... print("lining up numbers: %f" % num)
...
lining up numbers: 234.575742
lining up numbers: 14.465740
lining up numbers: 8.231235
lining up numbers: 19.423982
>>>
>>>
>>> for num in num_lst:
... print("lining up numbers: %.3f" % num)
...
lining up numbers: 234.576
lining up numbers: 14.466
lining up numbers: 8.231
lining up numbers: 19.424
>>>
>>>
>>> for num in num_lst:
... print("lining up numbers: %7.3f" % num)
...
lining up numbers: 234.576
lining up numbers: 14.466
lining up numbers: 8.231
lining up numbers: 19.424
>>>
>>>
>>>
>>> print("lining up numbers: %6.3f" % num)
File "", line 1
print("lining up numbers: %6.3f" % num)
^
IndentationError: unexpected indent
>>>
>>> for num in num_lst:
... print("lining up numbers: %6.3f" % f)
...
Traceback (most recent call last):
File "", line 2, in
NameError: name 'f' is not defined
>>>
>>>
>>> for num in num_lst:
... print("lining up numbers: %6.3f" % num)
...
lining up numbers: 234.576
lining up numbers: 14.466
lining up numbers: 8.231
lining up numbers: 19.424
>>>
>>>