Python Basics — Final Test

Three questions per lesson. Answer them all, then check your result.

  1. Getting Started with Python

    1. What does it mean that Python is interpreted?

  2. Getting Started with Python

    2. What is the result of 7 // 2 in Python?

  3. Getting Started with Python

    3. Which symbol starts a comment?

  4. Variables and Data Types

    4. What does type(3.0) return?

  5. Variables and Data Types

    5. Which expression correctly turns the string "12" into a number?

  6. Variables and Data Types

    6. Which variable name is valid in Python?

  7. Operators and Expressions

    7. What is the value of 2 + 3 * 4 ** 2?

  8. Operators and Expressions

    8. Which of these values is truthy?

  9. Operators and Expressions

    9. What does count += 4 do?

  10. Control Flow: if, elif, else

    10. How does Python define a block of code?

  11. Control Flow: if, elif, else

    11. In an if/elif/elif/else chain, how many branches execute?

  12. Control Flow: if, elif, else

    12. Which is the correct way to check for None?

  13. Loops: for and while

    13. How many numbers does range(2, 11, 3) produce?

  14. Loops: for and while

    14. What does the continue statement do?

  15. Loops: for and while

    15. When does a for ... else block run?

  16. Lists, Tuples, Sets and Dictionaries

    16. What does letters[1:4] return for a list of five items?

  17. Lists, Tuples, Sets and Dictionaries

    17. Which collection stores unique values with no order?

  18. Lists, Tuples, Sets and Dictionaries

    18. How do you safely read a possibly missing dictionary key?

  19. Functions and Scope

    19. What does a function return if it has no return statement?

  20. Functions and Scope

    20. What does *args collect in a function signature?

  21. Functions and Scope

    21. Why is def f(x, bag=[]) risky?

  22. Strings, Input and Files

    22. What type does input() always return?

  23. Strings, Input and Files

    23. What does text.replace("a", "b") do to the original string?

  24. Strings, Input and Files

    24. Why use with open(...) as f?

  25. Errors, Exceptions and Debugging

    25. Which exception does int("hello") raise?

  26. Errors, Exceptions and Debugging

    26. Which block always runs, exception or not?

  27. Errors, Exceptions and Debugging

    27. Why should you avoid a bare except:?

  28. Modules, Classes and Next Steps

    28. What is a Python module?

  29. Modules, Classes and Next Steps

    29. What is the role of __init__ in a class?

  30. Modules, Classes and Next Steps

    30. Why use a virtual environment?