Reputation: 29
name = raw_input ("What's your name? ")
print "Hello",name, "!"
It returns the following:
What's your name? John
Hello John !
How do I make it so that the space between John and ! doesn't appear?
This is in Python-2.7 by the way
Upvotes: 2
Views: 93
Reputation: 1633
since your name variable itself is a string you can use these instead:
print "hello"+name+"!"
or if it was't you can cast it to string using the str()
function.
Upvotes: 0
Reputation: 336128
Use the str.format()
method:
print "Hello {0}!".format(name)
This method of string formatting is the new standard in Python 3, and should be preferred to the
%
formatting [...] in new code.
Upvotes: 7
Reputation: 6658
You can do something like:
print 'Hello %s!' %(name)
This will return
Hello John!
Upvotes: 2