12,900+ practice questions · 144 exams · new questions added every week
Practice questions › Python Foundations › Python Programming Foundations

Python Foundations Python Programming Foundations practice questions

10 free questions with answers and explanations. Try each one, then tap “Show answer”.

  1. Operators

    1. What is the output of this code? print(17 // 5 * 2)

    • A. 1
    • B. 6
    • C. 2
    • D. 7
    Show answer

    Answer: B. 6

    17 // 5 = 3, then 3 * 2 = 6.

  2. Operators

    2. What is the output of this code? print(True + True)

    • A. 2
    • B. True
    • C. Error
    • D. 1
    Show answer

    Answer: A. 2

    True behaves like 1 in arithmetic.

  3. Lists

    3. What is the output of this code? a = [1, 2, 3] del a[0] print(a)

    • A. [2, 3]
    • B. [1, 2, 3]
    • C. [1, 2]
    • D. Error
    Show answer

    Answer: A. [2, 3]

    del removes the item at that index.

  4. Strings

    4. What is the output of this code? print(len(' hi '.strip()))

    • A. 6
    • B. 2
    • C. 4
    • D. 0
    Show answer

    Answer: B. 2

    strip() removes surrounding spaces.

  5. Control flow

    5. What is the output of this code? for i in range(2, 8, 3): print(i, end=' ')

    • A. 3 6
    • B. 2 5
    • C. 2 5 8
    • D. 2 3 4 5 6 7
    Show answer

    Answer: B. 2 5

    range(start, stop, step) stops before 8.

  6. Basics

    6. Which error does '2' + 2 raise?

    • A. SyntaxError
    • B. ValueError
    • C. NameError
    • D. TypeError
    Show answer

    Answer: D. TypeError

    You can't add a str and an int.

  7. Control flow

    7. What is the output of this code? for i in range(5): if i == 3: break print(i)

    • A. 4
    • B. 3
    • C. 5
    • D. 2
    Show answer

    Answer: B. 3

    break leaves the loop when i is 3.

  8. Basics

    8. Which keyword defines a function?

    • A. def
    • B. lambda only
    • C. function
    • D. func
    Show answer

    Answer: A. def

    lambda creates small anonymous functions.

  9. Control flow

    9. What is the output of this code? count = 0 for c in 'banana': if c == 'a': count += 1 print(count)

    • A. 3
    • B. 2
    • C. 6
    • D. 1
    Show answer

    Answer: A. 3

    'banana' has three a's.

  10. Basics

    10. Python uses ___ to group statements into blocks.

    • A. curly braces
    • B. BEGIN and END
    • C. semicolons
    • D. indentation
    Show answer

    Answer: D. indentation

    Consistent indentation (usually 4 spaces) is required.

Want more Python Foundations Python Programming Foundations questions?

Get fresh questions every day, focused on your weak topics, plus timed mock tests. Free to start.

Practise free in the web app Practise on Telegram

About the Python Foundations on Mock Night · Original practice questions; not affiliated with the exam board.