By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,773 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,773 IT Pros & Developers. It's quick & easy.

TypeError: 'NoneType' object is not iterable - Learning python, tad confused.

P: 2
I've been learing python from http://www.learnpython.org/page/Functions and in the functions lesson I've got stuck on the exercise for 2 days now.

As far as I can tell my code should work but when i run it, it returns TypeError: 'NoneType' object is not iterable. Can anyone explain why?

My code is:
Expand|Select|Wrap|Line Numbers
  1. def list_benefits():
  2.     print 'More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together'
  3. def build_sentence(info):
  4.     return '%s' % list_benefits + ' is a benefit of functions'
  5. def name_the_benefits_of_functions():
  6.     list_of_benefits = list_benefits()
  7.     for benefit in list_of_benefits:
  8.         print build_sentence(benefit)
  9.  
  10. name_the_benefits_of_functions()
Thanks Barry1.4
Jul 17 '12 #1

✓ answered by Smygis

Function list_benefits prints a set of strings. What i assume you want it to do is return a list.
So:
return ['More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together']

Share this Question
Share on Google+
3 Replies

Smygis
100+
P: 126
Function list_benefits prints a set of strings. What i assume you want it to do is return a list.
So:
return ['More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together']
Jul 18 '12 #2

P: 2
I think this is what you need to do to make it work . . .

change line 2-3 in your code
from
print 'More organized code', 'More readable code' , 'Easier code reuse' 'Allowing programmers to share and connect code together'
to
return "More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"

then line 5
from
return '%s' % list_benefits + ' is a benefit of functions!'
to
return info + " is a benefit of functions!"

That should work
Jul 19 '12 #3

P: 2
Thanks for both anwsers, they both worked well, and thanks to Smygis for helping me to understand.
Jul 19 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.