Hi, New to coding and cant seem to find the solution for this error (Python)

Question:

enter image description here

text = ["this","is","text"]
print(f"hello and {text, end=","}")
Input In [58]
    print(f"hello and {text, end=","}")
                                  ^
SyntaxError: f-string: expecting '}'

I am trying to remove brackets and commas while using an f string

……………………

Asked By: Passiv AHS

||

Answers:

It appears you are trying to print the contents of the list after the hardcoded string. So your code is first printing "hello and" and then the string representation of the list ‘text’. In order to print the elements of the list using an f string you can do:

text = ['this','is','text']
print(f"hello and {' '.join(text)}")
Answered By: E Joseph
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.