SyntaxError: ':' expected after dictionary key

SyntaxError: ‘:’ expected after dictionary key

In python SyntaxError: ‘:’ expected after dictionary key we face this error message when we miss the colon after the dictionary key in my code this is P but I need to type P: with a colon. We are human and we all do mistakes this is a normal scenario. To fix this error just add a colon after the dictionary key, For more clarification see the below example.

Wrong Code

dictionary = {
    "A": "A for Apple",
    "B": "B for Boll",
    "P" "P for Python"
}

print(dictionary["P"])

Error Massage

  File "/home/kali/python/webproject/error/main.py", line 4
    "P" "P for Python"
                     ^
SyntaxError: ':' expected after dictionary key

Wrong code line

    "P" "P for Python"

Correct code line

    "P": "P for Python"
  • Wrong action: “P” “P for Python”
  • Correct action: “P”: “P for Python”

Entire Correct Code line

dictionary = {
    "A": "A for Apple",
    "B": "B for Boll",
    "P": "P for Python"
}

print(dictionary["P"])

What is SyntaxError: ‘:’ expected after dictionary key?

In python we face this error message when we miss the colon after the dictionary key in my code this is P but I need to type P: with a colon.

How to fix SyntaxError: ‘:’ expected after dictionary key?

If you want to fix this error just add a colon after the dictionary key, For more clarification see the above example.

For more information Visit YouTube Channel.

Scroll to Top
Top 7 Gaming Project In python Save ₹25,000 Laptop under ₹11,999 Top 7 Funny error in Python Unicodeescape Most dangerous error in Python Hero Electric Battery Price In 2023