[Tutor] why do i get None as output

Alan Gauld alan.gauld at btinternet.com
Mon Sep 6 09:27:31 CEST 2010

"Roelof Wobben" <rwobben at hotmail.com> wrote 

def make_empty(seq):
    if type(seq) == type([]):
        while teller < len(seq):
            teller = teller + 1 
    elif type(seq) == type(()):
        tup2 = list (seq)
        while teller > tup2.len():
            teller = teller + 1
        seq = tuple(tup2)
        seq = ""
test = make_empty([1, 2, 3, 4])

But now I get None as output instead of []

Because None is the default return value from a function.
If you do not return a value (which you don;t in this case) then 
Python automatically returns None.

You need to return something from your make_empty function.

Also, if all you want to do is return an empty version of 
whatever has been passed in there are much easier 
ways of doing it! And in fact, a list of empty strings is 
not the same as an empty list...


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list