Python Introducing Lists Using Lists Mutability

Marcos Duran
Marcos Duran
1,922 Points

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?

1 Answer

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.

Marcos Duran
Marcos Duran
1,922 Points

Thank you boi. I get it now.