Why is my Python program printing parentheses and quotes where I don't expect them?

Viewed 88

I am getting this kind of weird output

My code is:

friends_name = ['Yashwanth','Koushik','Lalith','Narahari']
message = f"Hello buddy",friends_name[0]
print(message)
message = f'Hello buddy',friends_name[1]
print(message)

I am getting brackets and quotes in the output:

('Hello buddy', 'Yashwanth')
('Hello buddy', 'Koushik')
2 Answers

This is happening because you are printing a tuple

The variable will be a tuple because there is a value f'Hello buddy' and friends_name[1]

If you want to print them in one message

message = f'Hello buddy {friends_name[1]}'

This code: message = f"Hello buddy ,friends_name[0] is giving you a tuple, it is the same as message = (f"Hello buddy ,friends_name[0]).

What you probably want is an interpolation, in other words: message = f"Hello buddy {friends_name[0]}"

Related