Python Programming Introduction Quiz

Grade 6 · Technology · Quiz

Test your knowledge of Python basics including syntax, variables, and simple control structures.

Questions

  1. What will print("Hello" + " " + "World") display?

    1. Hello World
    2. "Hello" "World"
    3. HelloWorld
    4. Error
    Show answer

    Answer: Hello World

    The + operator concatenates strings in Python. 'Hello' + ' ' + 'World' produces 'Hello World'.

  2. Which of the following is a valid Python variable name?

    1. 2myVar
    2. my-var
    3. my_var
    4. my var
    Show answer

    Answer: my_var

    my_var is valid — it uses only letters and underscores. 2myVar starts with a number, my-var uses a hyphen, and my var has a space, all of which are invalid.

  3. What data type is the value 3.14 in Python?

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

    Answer: float

    3.14 is a floating-point number (float) because it has a decimal point. Integers have no decimal portion.

  4. What does the following code output? for i in range(3): print(i)

    1. 1 2 3
    2. 0 1 2
    3. 0 1 2 3
    4. 1 2
    Show answer

    Answer: 0 1 2

    range(3) generates 0, 1, 2. Python's range starts at 0 by default and stops before the given number.

  5. In Python, True and False must be capitalized.

    Show answer

    Answer: True

    Python is case-sensitive. 'true' and 'false' are not recognized as booleans — only 'True' and 'False' with capital first letters are.

  6. Which symbol is used to write a comment in Python?

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

    Answer: #

    The # symbol starts a comment in Python. // is used in JavaScript/C++, /* */ is for block comments in other languages, and -- is SQL.

  7. What will the following code do? x = 5 if x > 3: print("big")

    1. Print nothing
    2. Print 'big'
    3. Print '5'
    4. Cause an error
    Show answer

    Answer: Print 'big'

    Since x equals 5 and 5 > 3 is True, the indented block runs and prints 'big'.

  8. The keyword used to define a function in Python is ______.

    Show answer

    Answer: def

    The def keyword (short for define) is used to declare a function in Python, followed by the function name and parentheses.

Get a personalized course on Python Programming Introduction built around your child.