Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
edited by

This is the function to print all the values in a nested list (taken from Headfirst with Python) 

def printall(the_list, level):

    for x in the_list:

        if isinstance(x, list):

            printall(x, level=level + 1)

        else:

            for tab_stop in range(level):

                print("\t", end='')

        print(x)

The function is working appropriately. 

The function fundamentally prints the values in the list and on the off chance that there is a listed list, at that point, it print it by tab space. 

Only for a superior understanding, what does end=' ' do? 

I'm utilizing Python 3.3.5

For 2.7

f =  fi.input( files = 'test2.py', inplace = True, backup = '.bak')

for line in f:

    if fi.lineno() == 4:

        print line + '\n'

        print 'extra line'

    else:

        print line + '\n'

as of 2.6 fileinput doesn't uphold with. This code adds 3 additional lines and prints the added text on the 3rd new line. and afterward affixes a further 16 empty lines. 

1 Answer

0 votes
by (26.4k points)
edited by

The default value of the end is \n implying that after the print proclamation it will print another line. So essentially expressed end is the thing that you need to be printed after the print articulation has been executed 

Eg: - print ("hello",end=" +") will print hello +

Interested to learn python in detail? Come and Join the python course.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...