Python Fundamentals: Essential Interview Questions Quiz

Explore core Python concepts, features, syntax, and tools commonly discussed in interviews. This quiz helps reinforce basic Python knowledge for beginners and job seekers.

  1. Key Features of Python

    Which statement best describes Python's main features?

    1. Compiled, statically typed, limited libraries
    2. Easy-to-learn, dynamically typed, extensive libraries
    3. Hard-to-learn syntax, no object-oriented support
    4. Requires manual memory management and compilation

    Explanation: Python is highlighted for its readable syntax, dynamic typing, and large library support. The second and fourth options incorrectly claim Python is compiled and requires manual management. The third option is incorrect because Python provides object-oriented features and is known for its easy syntax.

  2. List, Tuple, and Set Differences

    What is a key difference between a Python list and a tuple?

    1. Tuples allow duplicates; lists do not
    2. Lists are mutable; tuples are immutable
    3. Lists are immutable; tuples are mutable
    4. Lists are unordered; tuples are ordered

    Explanation: Lists can be changed after creation while tuples cannot. The second option reverses the properties. Both lists and tuples allow duplicates, so the third is incorrect. Lists are ordered, so option four is also incorrect.

  3. Understanding Decorators

    What do Python decorators primarily do?

    1. Delete unused files
    2. Modify the behavior of a function or method
    3. Convert code to machine language
    4. Sort lists automatically

    Explanation: Decorators adjust how functions behave by wrapping them, without altering their structure. The other options are unrelated—none involve function behavior modification.

  4. Shallow Copy vs Deep Copy

    How does a shallow copy differ from a deep copy in Python?

    1. Shallow copy stores data externally; deep copy keeps it internal
    2. There is no difference between the two
    3. Shallow copy duplicates everything; deep copy shares references
    4. Shallow copies references; deep copies all objects independently

    Explanation: A shallow copy shares object references, while a deep copy duplicates the full structure. The second option mistakenly swaps definitions. The third is unrelated; the fourth is incorrect since the two methods behave differently.

  5. Purpose of *args and **kwargs

    What is the main purpose of *args and **kwargs in Python function definitions?

    1. To disable functions
    2. To restrict arguments to integers only
    3. To allow passing variable numbers of arguments
    4. To comment code better

    Explanation: They let functions accept variable numbers of both positional and keyword arguments, increasing flexibility. The other options are either unrelated or incorrect regarding their purpose.

  6. Python's Memory Management

    Which method does Python use to manage memory automatically?

    1. Reference counting and garbage collection
    2. Only garbage bins
    3. Manual pointer allocation
    4. External tools only

    Explanation: Python uses reference counting and a garbage collector to manage memory, making manual memory management unnecessary. Options two and four are incorrect; option three is not relevant terminology.

  7. Difference Between is and ==

    In Python, what does the 'is' operator compare?

    1. If two variables have equal values
    2. If a variable is defined
    3. Whether two objects are the same in memory
    4. Whether an object is callable

    Explanation: 'is' checks for identity (same object in memory), not value. The second option describes '=='. The third and fourth options do not apply to 'is'.

  8. Lambda Functions

    Which best describes a Python lambda function?

    1. A built-in function for sorting
    2. A reserved keyword for loops
    3. A small, anonymous function using the lambda keyword
    4. A type of error handler

    Explanation: Lambda functions are simple anonymous functions created with the 'lambda' keyword. They are not built-in sorters or related to error handling or loop keywords.

  9. Modules vs Packages

    What is the difference between a Python module and a package?

    1. A package cannot contain modules
    2. Both are single files
    3. A module requires __init__.py
    4. A module is a single file; a package is a directory with __init__.py

    Explanation: A module refers to a single .py file, while a package is a directory of modules containing __init__.py. The other options misunderstand the relationship between modules and packages.

  10. Exception Handling

    Which keywords are commonly used to handle exceptions in Python?

    1. begin, rescue, ensure, repeat
    2. try, except, else, finally
    3. catch, throw, end, check
    4. handle, ignore, retry, escape

    Explanation: Python uses 'try', 'except', 'else', and 'finally' for exception handling. The second and third options list keywords from other languages or made-up ones, and the fourth contains words not used in Python exception handling.