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 Introducing Lists Meet Lists Addition

Son-Hai Nguyen
Son-Hai Nguyen
2,481 Points

print ("there are" , len(attendees) , "attendees currently") is actually printing a list?

Hi guys,

I tried

print ("there are" + len(attendees) + "attendees currently") 

and python gave me an TypeError: must be string bot integer. But how Craig changed the print function into

print ("there are" , len(attendees) , "attendees currently")

and it worked? is it in the () a list so that didnt care if it's an integer or a string?

Thanks guys.

3 Answers

Steven Parker
Steven Parker
231,275 Points

The "print" function can handle multiple comma-separated arguments that are different types.

But to perform concatenation with the "+" operator, the operands on both sides of it must be strings.

Dan B
Dan B
6,155 Points

There are also unnecessary spaces in your code.

The teacher's code was exactly:

print("There are", len(attendees), "attendees at the event")

Note that there are no spaces before the comma separators and no space after the print function. Also remember that using the addition sign means that you want python to add those parameters together. In this case you are trying to add a string and a function together with another string which will not work.

Son-Hai Nguyen
Son-Hai Nguyen
2,481 Points

Thanks Steven. I’ve just tried it in Maya Python and it returned the same error as well.