Use of print "str1" + "str2"


#1


https://www.codecademy.com/courses/python-beginner-sRXwR/3/1?curriculum_id=4f89dab3d788890003000096#


I expect that print command ends with first "str1 " but there are two strings so shouldn't they both be inside something like brackets to work.


Replace this line with your code. Do not remove the backticks that are above or below this line.
print "Spam "+"and "+"eggs"


my doubt is that shouldn't the print command end at "Spam" since print will look for two "


#2

@cypas
Could you please print your code so we can help you check what's wrong?


#3

i have added the code


#4

@cypas
I know nothing about Python (but it's quite similar to Ruby) but I think why it will print the whole line:

It will use concatenation which will add the string together before printing it.


#5

If the concatenation operators are in the quote marked string, they will print. Think of it in terms like this:

str1 = "start of string "
str2 = "middle of string "
str3 = "end of string"
print str1 + str2 + str3

# start of string middle of string end of string

#6

thanks that cleared my doubt perfectly