Unwanted parenthesis in my output

I’m very new to Python (my 2nd day) and I have spent hours trying to work out why I have parenthesis in my sentence. This is what I have written.

famous_person = “Clifford T Ward”
quote = ‘once said, “I could be a millionaire, if I had the money.”’
message = (famous_person,quote)
print(message)

This is what comes out. Plus I don’t want the ’ around his name and at the end.

(‘Clifford T Ward’, ‘once said, “I could be a millionaire, if I had the money.”’)

Sorry for such a dumb question, but any help would be great.

Thanks

Mike

A quick question: what you think this line:

…actually does?

Is it a variable?

I don’t know much I’m afraid.

The exercise was too.

Find a quote from a famous person, print the quote and the name of the person using a variable called famous_person
Then compose your message and represent it with a new variable called message and print the message.

Thanks for your help

Mike

Well, the line in my question creates a tuple. Long story short: the message contains a pair of strings.

When you pass a tuple to print(...) it prints what you described: a value in parentheses with text in apostrophes. If you want to print it as a concatenated text then you have got a few options:

  1. You can do just a concatenation: message = famous_person + ' ' + quote
  2. Use a f-string: message = f"{famous_person} {quote}"
  3. Pass it to the print(...) using arguments expanding: print(*message)

It is now up to You what you chose (and which one You understand) :wink:

No such thing as a dumb question. :slight_smile:

Welcome to Python!

Beyond what @FelixLeg said, here’s a great tutorial on F-Strings, which my you might find helpful: Python's F-String for String Interpolation and Formatting – Real Python

Hi

I found this one to work for me & thank you very much for your help.

Mike

message = f"{famous_person} {quote}"

1 Like

Thank you, I’ll be sure to look at it, every extra help is always great.

Mike

1 Like

Reference:

The assignment wanted you to “compose the message”, like described above. But you should also be aware of this basic technique with the print function:

1 Like