string concatenation

+1 s kon · November 14, 2014

hello = "Hello"
world = 'World'

hello_world = hello + world
print(hello_world)



Hi,
i am getting output  "HelloWorld" but i want to print "Hello World" please help me anybody thank you



Post a Reply

Replies

Oldest  Newest  Rating
+1 Colonel Panic · November 15, 2014
You have to add a space to have a space.  

>>> hello = "Hello"
>>> world = 'World'
>>> hello_world = hello + world
>>> print(hello_world)
HelloWorld
>>> hello_world = hello + " " + world
>>> print(hello_world)
Hello World


There are better ways to do this.    In Python 2.x its:
>>> print hello, world
Hello World

In Python 3.x it is:
>>> print("%s %s" % (hello, world))
Hello World
  • 1

Python

107,014 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator