12.Print out a list item by item in a function


Hello ,

Can anyone tell me if exists, which is the difference between:

n = [3, 5, 7]

def print_list(x):
    for i in range(len(x)):    
        print x[i]


n = [3, 5, 7]

def print_list(x):
    for i in range(0, len(x)):    
        print x[i]


I mentioned because both are validated as ok by the programm.


in your first program, range has one argument (stop value), your second program, range has two arguments (start and stop value)

if no start value is provided for range, it uses default value (0)

so, no significant difference in the programs


which version is recommended?


i would like to quote knut:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

If you don't know who donald knut is, please google.

If you manage to read the books by donald knut, you can send your CV to bill gates and you will directly get hired


too much attention to details is the root.... and coding does that: trains your attention to details....this is the "bug".


Python is the first programming language I've started to learn 1 month ago on Codecademy.And suprisingly I became like "addicted".

What you are saying it seems to me like a Far Away Land....But never say never.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.