0

I have the following code:

d= {'q': 23 , 2:5 ,  3: 'w'}
d['q']    # this gives 23  
f'adf {d[2]}'     # this generates : adf 5  (As expected)
f'adf {d['q']}'     # this generates syntax error, I was expecting : adf 23

Any explanation of what I am missing?!

1
  • 2
    Use double-quotes to avoid having nested quotes: f'adf {d["q"]}' Commented Jan 23, 2020 at 17:07

1 Answer 1

1

The single quotes around q are ending the string, so you get a syntax error. you could use double quotes instead:

f'adf {d["q"]}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.