+ 1
Why is 'Hello' +'World'='Hello World' and not 'HelloWorld'... but ' spam' +'eggs'='spameggs'?
It was given here in this study material.
3 Réponses
+ 11
I've just checked, there is no error in the course, "Hello " + "world" (with a space after Hello inside the quotes) is used.
+ 4
There must be some mistake or may be space if you are referring to such study material
If you try this in editor you will come to know that it will print
print ('Hello' + 'World')
HelloWorld #this will be the output.
(+) is concatenation operator and used to join two strings
+ 1
Hi Jaya,
I'm not sure which specific part of the course you're referring to, but hope this helps...
print('Hello' + 'World')
HelloWorld
print('Hello ' + 'World')
Hello World
notice the only difference in the line of code is a 'space' between the "o" and the '
Also, we can look at Spam and Eggs
print("Spam" + "Eggs")
SpamEggs
print("Spam " + "Eggs")
Spam Eggs
It is important to make sure either your "Spam" string our your "Eggs" string contains a space. For example, you could put the space before the E in Eggs to get the same result! (see below)
print("Spam" + " Eggs")
Spam Eggs
I hope this helps you! I am a beginner myself and my best advice would be "practice, practice, practice" Good luck & have fun!