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 Using Lists Mutability

Bringing together strings and variables with '+' vs ','

I have a question about putting together strings and variables using operands and commas.

In the previous quiz the output was correct using:

print("* ", continent) which outputed "* Asia" but the quiz did not accept. print("* " + continent) which outputed the same thing and was accepted.

At a deeper level what are the differences or limitations between these two?

2 Answers

boi
boi
14,241 Points

They both have different nature and they are not the same the comma makes it a tuple and + operand just concatenates it. try this

name = "Marcos"
a = "* " , name

b = "* " + name

print(a)
print(b)

print(len(a))

print(len(b))

also try this

help(a)

help(b)

the a will be stored as a tuple and the b will be more like a single string.

Thank you boi. I get it now.