0
alien_o = {"Colour" : "Green"}
print(f"The colour is now {alien_o["Colour"]}.")

What's wrong with these lines of code? The closing bracket and the curly bracket is affected by the quotes, and I don't understand why.

ale123
  • 15
  • 7
  • 3
    Don't use double quotes inside expression – deadshot Jun 11 '22 at 19:48
  • 3
    Use single quotes `'` or triple quotes `'''` for the f-string. Something like this `print(f'The colour is now {alien_o["Colour"]}.')`. The rule is: if you are using single quotes outside, use double quotes inside and vice-versa. – accdias Jun 11 '22 at 19:48
  • Yup. You can't do backslashes. F-strings are super convenient, but they do have some limitations, which are fortunately easy to manage – Mad Physicist Jun 12 '22 at 05:25

1 Answers1

4

It mixes up the ", try using 'Colour' instead of "Colour".

Because it thinks that the format string is f"The colour is now {alien_o[", which is not what you want.

Edward Ji
  • 745
  • 8
  • 19