Five Fun & Easy Python Interview Questions! — Questions & Answers

This quiz contains 5 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.

  1. Question 1: Reversing Generators

    Which of the following will safely reverse the contents of a Python generator if you know the generator has finite length?

    • A. list(reversed(generator))
    • B. reversed(list(generator))
    • C. generator.reverse()
    • D. reverse(generator)
    • E. list(generator).reverse()
    Show correct answer

    Correct answer: B. reversed(list(generator))

  2. Question 2: Python 2 vs. Web Frameworks

    Which statement correctly describes the primary difference between 'xrange' and a web framework in Python?

    • A. 'xrange' is for web development, while a web framework is for iteration
    • B. 'xrange' only works in Python 3, web frameworks only in Python 2
    • C. 'xrange' is a built-in used for generating numbers, while a web framework is used for building web applications
    • D. 'xrange' must be imported from a library, web frameworks are always built-in
    • E. Both are exactly identical in function
    Show correct answer

    Correct answer: C. 'xrange' is a built-in used for generating numbers, while a web framework is used for building web applications

  3. Question 3: String vs. List Comprehension

    If you evaluate 'type("hello") == str' in Python, what will the result be?

    • A. False
    • B. list
    • C. TypeError
    • D. True
    • E. None
    Show correct answer

    Correct answer: D. True

  4. Question 4: Python Syntax and Docstrings

    What is a valid way to write a docstring for a function in Python?

    • A. /* This adds two numbers */
    • B. function docstring: 'Adds two numbers'
    • C. """Adds two numbers"""
    • D. docstring(adds two numbers)
    • E. // Adds two numbers
    Show correct answer

    Correct answer: C. """Adds two numbers"""

  5. Question 5: Objects and Numbers in Python

    When you create a number in Python using 'x = 5', what is 'x' actually?

    • A. A variable storing a raw numeric value only
    • B. An object of type int
    • C. A function
    • D. Always a string
    • E. Just an address
    Show correct answer

    Correct answer: B. An object of type int