0

I am trying to print this line and the string is set:

print('Hello',name,'!','You were born in', age_new)

and I keep getting:

Hello Amanda ! You were born in 2005

How do I get the exclamation point left one space?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
agunner23
  • 1
  • 1
  • 2
    See https://docs.python.org/3/library/functions.html#print. Or use any of the various ways to build a string rather than passing separate arguments to print. – jonrsharpe May 21 '21 at 19:59
  • 1
    Really do follow the duplicate links up top -- the answers you have now (as they were first added; things have improved slightly within the 5-minute edit window) are not modern best practice; the answers on the older copies of the question are better (as one would expect, since those copies have had more time to collect in-depth answers, for those answers to be commented on/edited/refined, etc). – Charles Duffy May 21 '21 at 20:01
  • Thank you very much! – agunner23 May 21 '21 at 20:30

2 Answers2

1

When using print('text','text2') you will automatically receive a space. So instead you can use old fashion + for concatinate.

name,age_new = 'bob',45
print('Hello',name+'!','You were born in', age_new)

But I highly highly suggest you move away from + and , and use f-strings. They are easy and efficient.

name,age_new = 'bob',45
print(f'Hello {name}! You were born in {age_new}')
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44
-2

How about

print('Hello', name + '!','You were born in', age_new)