[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):
    word2=""
    teller=0
    if type(seq) == type([]):
        teller=0 
        while teller < len(seq):
            seq[teller]=""
            teller = teller + 1 
    elif type(seq) == type(()):
        tup2 = list (seq)
        while teller > tup2.len():
            tup2[teller]=""
            teller = teller + 1
        seq = tuple(tup2)
    else:
        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...


HTH

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list