Python Basic Fundamentals Quiz

Challenge your understanding of Python basic fundamentals with these easy, concise questions. This quiz covers key Python concepts like data types, syntax, variables, and control flow, designed for beginners to strengthen their core programming skills.

  1. Python Variable Assignment

    Which of the following is the correct way to assign the value 10 to a variable named 'num' in Python?

    1. int num = 10
    2. num: 10
    3. num == 10
    4. num = 10

    Explanation: In Python, the correct way to assign a value is using a single equals sign as in num = 10. 'int num = 10' is a syntax used in other programming languages, but not in Python. 'num == 10' is a comparison, not an assignment. 'num: 10' does not assign a value; it is incorrect in this context.

  2. Python Data Types

    If you execute the Python statement name = 'Alice', what data type does the variable 'name' have?

    1. integer
    2. boolean
    3. float
    4. string

    Explanation: When you assign text within quotes to a variable in Python, such as 'Alice', its data type is string. 'Integer' is for whole numbers, which doesn't fit here. 'Float' represents decimal numbers, and 'boolean' is for True or False values, making them incorrect in this case.

  3. Python Indentation

    What will happen if you forget to indent the code inside a Python 'for' loop?

    1. You will get an IndentationError
    2. Nothing happens; indentation is optional
    3. The loop will run without errors
    4. The program will silently skip the loop

    Explanation: Forgetting to indent inside a Python loop leads to an IndentationError because indentation defines blocks in Python. The code will not run without errors if indentation is missing. Indentation is not optional in Python. The interpreter will not simply skip the loop but will instead stop with an error.

  4. Python Comment Syntax

    Which symbol is used to start a single-line comment in Python?

    1. --
    2. /*
    3. #
    4. //

    Explanation: The '#' symbol begins a single-line comment in Python, making any text after it on the same line ignored by the interpreter. '//' is used in some other languages, but doesn't comment in Python. '--' and '/*' are not recognized as comment symbols in Python; they are used elsewhere.

  5. Python Looping Structures

    Which Python keyword is used to create a loop that repeats while a given condition is True?

    1. until
    2. while
    3. loop
    4. repeat

    Explanation: The 'while' keyword initializes a loop that continues as long as the specified condition remains True in Python. 'repeat', 'until', and 'loop' are not valid Python keywords for looping; they may be used in other languages or are simply incorrect here. Only 'while' functions correctly for this purpose.