Python Fundamentals and Core Syntax Challenge Quiz

Test your mastery of foundational Python concepts such as printing, comments, indentation, variable rules, and basic input/output. Each question is designed to assess your awareness of fine syntax details and language behavior.

  1. Print Statement Behavior

    When executing print('Hello', 'World', sep='*', end='?'), what is the exact output produced?

    1. Hello*World
    2. Hello* World?
    3. HelloWorld?
    4. Hello World?
    5. Hello*World?
  2. Comment Syntax Correctness

    Which of the following lines will not result in a syntax error if inserted in a Python script?

    1. # This is a comment
    2. -- This is a comment
    3. u003C!-- This is a comment --u003E
    4. ** This is a comment
    5. // This is a comment
  3. Indentation Impact

    Given this code snippet, what happens?nnx = 3n if x u003E 2:n print('Hi')

    1. IndentationError is raised
    2. It prints 'Hi' with no errors
    3. NameError: name 'print' is not defined
    4. TypeError: 'int' object is not callable
    5. SyntaxError: unexpected EOF while parsing
  4. Variable Name Validity

    Which variable name below is not valid in Python?

    1. my_var2
    2. my-var
    3. MyVar
    4. _myVar
    5. var_3
  5. Type Preservation After Input

    What is the type of variable 'x' after executing x = input('Enter something: ')?

    1. list
    2. str
    3. float
    4. bool
    5. int
  6. Accurate Commenting Out of Multiple Lines

    Which is the most Pythonic way to comment out several lines of code?

    1. Surround with // and //
    2. Begin each line with --
    3. Begin each line with #
    4. Surround with u003Cu003C and u003Eu003E
    5. Surround with /* and */
  7. String Concatenation Output

    What is printed by print('py' + str(3*2))?

    1. py*6
    2. py 6
    3. py32
    4. py3*2
    5. py6
  8. Using Escape Characters

    Given print('Line1 Line2'), what is the output?

    1. Line1 Line2
    2. Line1 Line2
    3. Line1nLine2
    4. Line1/Line2
    5. Line1nLine2
  9. Determining Data Types

    What value does type(12.0) return?

    1. 'float'
    2. u003Cclass 'float'u003E
    3. float
    4. u003Ctype 'float'u003E
    5. u003Cclass 'int'u003E
  10. Multiple Assignment Nuances

    If you write a, b = 1, 2 in Python, what are the values of a and b afterwards?

    1. a = [1, 2], b = None
    2. a = '1', b = '2'
    3. a = None, b = [1, 2]
    4. a = 1, b = 2
    5. a = 2, b = 1
  11. Printing Without Newline

    Which print statement suppresses the automatic newline at the end?

    1. print('Done', stop='')
    2. print('Done', newline='')
    3. print('Done', end='')
    4. print('Done', finish='')
    5. print('Done', noline='')
  12. Variable Reassignment

    What is the value of y after executing: y = 7; y = y + 2; y = str(y)?

    1. 7
    2. '7'
    3. TypeError is raised
    4. 9
    5. '9'
  13. Illegal Expression Use

    Which of the following will produce a SyntaxError if entered as a statement?

    1. x = True
    2. x = 1_000_000
    3. 3x = 9
    4. x = 3 // 2
    5. x, y = 1, 2
  14. Input Processing and Casting

    If the user enters '25' when prompted by age = input('Age: '); age = int(age), what is the value and type of 'age'?

    1. '25', int
    2. '25', str
    3. 25, str
    4. 25, int
    5. SyntaxError
  15. Indentation in Nested Structures

    What will be the result of this code block?nx = 2nif x u003E 1:n if x u003E 0:n print('A')n print('B')nprint('C')

    1. A B
    2. A B C
    3. C B A
    4. A C B
    5. B A C
  16. Variable Initialization Rules

    What happens if you reference a variable in Python before assigning it a value, such as with print(z)?

    1. It prints 'z'
    2. NameError is raised
    3. AttributeError is raised
    4. It prints 0
    5. It prints nothing