You might want to learn to use pythons inbuild help.
Open python 3.x shell and give it the command: help(print)
it will display:
Help on built-in function print in module builtins:
print(value, ..., sep=' ', end='\n', file=sys.stdout)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
I get it. But when in this complete module, I'm still digesting it:
# This module prints out nested lists
def crack(listname, level):
for deeper_list in listname:
if isinstance(deeper_list, list):
for l in range(level):
print("\t", end=' ')
#This will print out the nested list with tab-stops according to the level.
# E.g. numbers = [1, 2, 3, [4, 5]]
prints an according number of tabs and stays in the same line. If you left out the end=' ' each time a newline would be printed and the tabs would be lost (the next print then starts at the beginning of the new line). (BTW. I would prefer end='')
Edit: end='' means end=' ' with the space inbetween removed. Might be hard to read here.
Edit2: Maybe your problem with understanding is not the print syntax, but the recursion the module uses?
This post has been edited by Nallo: 24 April 2011 - 07:14 AM