Skip to content
Question 49 of 97

Q.Identify the invalid Python statement from the following: (A) d = dict() (B) e = {} (C) f = [] (D) g = dict{}

West Bengal WbchseCBSE Class XII Board 2024MCQ· 1mImportance★★★★★
51% · 49/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Python provides specific syntax for creating empty dictionaries (dict() or {}) and lists ([] or list()); dict{} is not a valid way to create a dictionary and will result in a syntax error. The invalid statement is (D).

Concept and Intuition

In Python, data structures like lists and dictionaries are fundamental for organizing data. Python offers multiple ways to create these structures, primarily through two methods:

  1. Constructor functions: Using the type name followed by parentheses, like list() or dict(). These are functions that return an empty instance of that type.
  2. Literal syntax: Using special symbols that directly represent the structure, like [] for an empty list or {} for an empty dictionary. This is often more concise and idiomatic Python.

Both methods achieve the same result for creating empty structures, but they are distinct syntactical forms. The key is to use the correct syntax for each method.

Step-by-step Analysis

  1. Statement (A): d = dict()

    This statement uses the dict() constructor function to create an empty dictionary. The dict() function, when called without arguments, returns a new, empty dictionary. This is a perfectly valid and common way to initialize an empty dictionary in Python.

    After this statement, d will be an empty dictionary, equivalent to {}.

  2. Statement (B): e = {}

    This statement uses the literal syntax for creating an empty dictionary. Curly braces {} are the standard way to define dictionary literals in Python. When empty, they represent an empty dictionary. This is also a perfectly valid and very common, often preferred, way to initialize an empty dictionary.

    Watch out

    While {} creates an empty dictionary, if you need an empty set, you must use set(). An empty set cannot be created with {} because {} is reserved for empty dictionaries. For example, type({}) is <class 'dict'>, while type(set()) is <class 'set'>.

  3. Statement (C): f = []

    This statement uses the literal syntax for creating an empty list. Square brackets [] are the standard way to define list literals in Python. When empty, they represent an empty list. This is a valid and widely used way to initialize an empty list.

    Alternatively, one could use f = list(), which also creates an empty list using the list() constructor.

  4. Statement (D): g = dict{} …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.