Simple Python Interview Quiz Quiz

Explore key Python topics often encountered in interviews with these easy multiple-choice questions. Great for beginners or those preparing for Python fundamentals.

  1. Python File Extension

    What is the standard file extension for Python files?

    1. .py
    2. .python
    3. .pt
    4. .txt

    Explanation: The correct extension for Python files is .py. The options .pt and .python are incorrect and not recognized by Python interpreters. .txt is a generic text file format, not specific to Python.

  2. Printing Output

    Which function is commonly used in Python to display output to the screen?

    1. display()
    2. echo()
    3. output()
    4. print()

    Explanation: The print() function is used to display output in Python. echo() is used in some other languages, not Python. display() and output() are not standard Python functions for showing output.

  3. Python Comments

    How do you write a single-line comment in Python?

    1. // This is a comment
    2. /* This is a comment */
    3. <!-- This is a comment -->
    4. # This is a comment

    Explanation: Single-line comments in Python start with #. The // and /* */ styles are used in languages like JavaScript or C. <!-- --> is used in HTML and not for Python comments.

  4. Python Indentation

    In Python, what is indentation used for?

    1. Skipping lines
    2. Styling code
    3. Defining code blocks
    4. Declaring variables

    Explanation: Indentation in Python determines code blocks, especially for functions and control structures. It is not about styling, declaring variables, or skipping lines, which are incorrect or unrelated uses.

  5. Data Types

    Which one is a numeric data type in Python?

    1. bool
    2. list
    3. str
    4. int

    Explanation: int stands for integer and is a numeric data type. str is for strings, list is for collections, and bool is for Boolean values, not numbers.

  6. Variables in Python

    Which of these is a valid way to assign a value to a variable in Python?

    1. x: 5
    2. let x = 5
    3. x = 5
    4. int x = 5

    Explanation: x = 5 assigns the integer 5 to variable x in Python. let and int as prefixes are not used in Python. x: 5 is incorrect syntax for variable assignment in Python.

  7. String Concatenation

    Which operator is used to join two strings in Python?

    1. -
    2. *
    3. +
    4. &

    Explanation: The + operator joins two strings. -, *, and & do not perform string concatenation in Python.

  8. List Data Structure

    Which symbol is used to create a list in Python?

    1. < >
    2. { }
    3. ( )
    4. [ ]

    Explanation: Lists in Python are created using square brackets [ ]. Curly braces { } are for dictionaries or sets, parentheses ( ) are for tuples, and < > are not used for data structures.

  9. Function Definition

    Which keyword is used to define a function in Python?

    1. define
    2. def
    3. func
    4. function

    Explanation: The correct keyword to define a function in Python is def. func, function, and define are not valid Python keywords for creating functions.

  10. Looping Through a List

    Which loop is commonly used to iterate over items in a list in Python?

    1. repeat
    2. foreach
    3. for
    4. do while

    Explanation: The for loop is standard in Python for iterating through a list. do while and repeat do not exist in Python, and foreach is not a Python keyword.