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


#1

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]
print_list(n)

and

n = [3, 5, 7]

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

?

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


#2

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


#3

which version is recommended?


#4

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


#5

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


#6

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.


#7

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