0

I have some code like:

usernames = ('admin', 'Jaden', 'Milky', 'Huff')
for username in usernames:
    if username == 'admin':
        print("Hello", username.title(),', thanks for coming')
    else:
        print("Sup", username.title(), 'How you feeling?')

which outputs:

Hello Admin , thanks for coming
Sup Jaden How you feeling?
Sup Milky How you feeling?
Sup Huff How you feeling?

How do I get the comma to sit where it should after Admin, without a space in between?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
BFP2044
  • 9
  • 1
  • 1
    Use a format string: `print("Hello {}, thanks for coming".format(username.title()))`. – Nathaniel Ford Aug 12 '22 at 03:19
  • @NathanielFord That's not a format string, that's using the `format`method. With an f-string you would have `print(f"Hello {username.title()}, thanks for coming")`. – Matthias Aug 12 '22 at 07:30
  • @Matthias Ok. Both of them are string interpolation, string formatting or format string. The key was that the OP was given the term 'format string'. But, sure. The precise definition of 'format string' would be the `f"thing {variable} thing"`. The question was already closed so I couldn't post the more elaborate answer. I'm not sure what the point was of being pedantic here. – Nathaniel Ford Aug 12 '22 at 08:57
  • I decided to comment since that isn't a format string and I don't want the asker to learn the wrong terminology. – Matthias Aug 15 '22 at 14:21

1 Answers1

0

Using commas , result in an added space, so you have to use +:

usernames = ('admin', 'Jaden', 'Milky', 'Huff')
for username in usernames:
    if username == 'admin':
        print("Hello " + username.title() + ', thanks for coming')
    else:
        print("Sup " + username.title() + ' How you feeling?')
DialFrost
  • 1,610
  • 1
  • 8
  • 28