Dice
Dice

Reputation: 23

Spaces in Python 3

I've just started learning Python 3 - and programming in general - and can't figure out how to put a space between Hello and a variable.

name = Amy 
print ('Hello' + name + '!' *3)

That prints out as HelloAmy!!! How do you put a space between Hello and Amy?

Thanks

Upvotes: 2

Views: 229

Answers (3)

A Israfil
A Israfil

Reputation: 519

Its as simple as adding a space withing the quotes. The interpreter prints what is directly given in the quotes.

print ('Hello ' + name + '!' *3)

Upvotes: 0

Carcigenicate
Carcigenicate

Reputation: 45736

Just add a space in the existing string:

name = 'Amy'
print ('Hello ' + name + ('!' * 3))
#            ^ Space

or if 'Hello' was defined by another variable, you could have just added another string containing only a space:

print (hello_string + ' ' + name + ('!' * 3))

I assuming Amy should have been in quotes

Upvotes: 0

OA617
OA617

Reputation: 76

print ('Hello ' + name + '!' *3)

Upvotes: 1

Related Questions