[Tutor] Function question

Peter O'Doherty kevinpeterodoherty at gmail.com
Sat Mar 25 06:01:21 EDT 2017


Hi,

Apologies for the very basic question but could anyone explain the 
behaviour of these two functions (in Python3.5)?

def myFunc(num):
     for i in range(num):
         print(i)

print(myFunc(4))
0
1
2
3
None #why None here?


def myFunc(num):
     for i in range(num):
         return i

print(myFunc(4))
0 #why just 0?

Many thanks,
Peter




More information about the Tutor mailing list