Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Loop

Unsupported operand type(s) for +: 'NoneType' and 'str' - even though I'm working with strings only

I think this might be a bug. I have a list of strings and when looping through them I'm concatenating " World" to it. It shows me an error message that makes no sense in my opinion as it's only strings I'm working with. When I type the same code into the Python shell it works perfectly so it has to be a bug on this website.

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for hello in hellos:
    print(hello) + " World"

For python3 print is a function that takes one string argument.

The reason that it might be(didn't worked in mine though) working fine is because you are working in a Shell, try to make a file out of it and then try running it. I am sure there would be errors.

The solution is what Reyam suggested in his answer.

2 Answers

Reyam Marcos
PLUS
Reyam Marcos
Courses Plus Student 10,367 Points
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for hello in hellos:
    print( hello + " World")

hope it helps

Thank you! I didn't realize this course was in Python 3, but now it worked!

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

print() is a function that doesn't return a value (nothing comes out of print(), it just sends characters to the terminal. So, as far as Python is concerned, it's value is None. When you do print() + "something", Python tries to add None to "something" which it can't do.