[Tutor] Return T/F vs print T/F
Sivaram Neelakantan
nsivaram.net at gmail.com
Sat Feb 4 15:38:09 CET 2012
While trying out code, I have trouble following the difference between
return True vs print True and the same with False. If I use return
for the True/False statements, nothing gets printed. Why? And if I
add a print before the function call I get an output like
>>>True
None
--8<---------------cut here---------------start------------->8---
def first(word):
return word[0]
def last(word):
return word[-1]
def middle(word):
return word[1:-1]
def palin(text):
if first(text) == last(text):
# print first(text), last(text), middle(text), len(middle(text))
if len(middle(text)) == 0:
print True
else:
palin(middle(text))
else:
print False
palin("o")
palin("nxon")
palin("nooxooxoon")
print palin("nabban")
--8<---------------cut here---------------end--------------->8---
sivaram
--
More information about the Tutor
mailing list