What is the difference between , and + when combining strings?


The code below works

parrot = "Norwegian Blue"
print "This word has" ,len(parrot), "words!"

but this doesn’t?

parrot = "Norwegian Blue"
print "This word has " + len(parrot)+ "words!"

Can anyone explain why?


The comma there is part of the print statement, it doesn’t interact with strings at all, it isn’t an operator, it’s “this is what a print statement looks like when you have multiple values to print”

It’s similar to how you can send multiple arguments to a function

Oh and, when you use the word “work” you have to explain what you intend.


The difference between the (,)and(+) is very simple “,” dose not join the given string or number(any thing ) ,but “+” operator just like adding (can be integer or may be a string )


in the line of code where you are using (+) to concatenation, if you convert len(parrot) to string like so: str(len(parrot)) it will concatenate the out put of len(parrot) with the rest of the string, you will have to put a whitespace before “words!”.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.