On 06/09/2010 8.34, Roelof Wobben wrote:
Hello,

I have this programm:
...
def make_empty(seq):
"""
 >>> make_empty([1, 2, 3, 4])
[]
 >>> make_empty(('a', 'b', 'c'))
()
 >>> make_empty("No, not me!")
''
"""
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])
print test

But now I get None as output instead of []

I would add a line like:

return seq

at the end of the  make_empty  function.


Can anyone explain why that happens ?
I think Python doesn't know what exactly is the value you need to receive from the make_empty function. That's why I'd make it clear. Otherwise, you know what happens...

I quote the following from
http://diveintopython.org/getting_to_know_python/declaring_functions.html
"In fact, every Python function returns a value; if the function ever executes a return statement, it will return that value, otherwise it will return None, the Python null value."

Roelof
Francesco
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3115 -  Data di rilascio: 
09/05/10 08:34:00
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to