Python Basics — Final Test
Three questions per lesson. Answer them all, then check your result.
Getting Started with Python
1. What does it mean that Python is interpreted?
Getting Started with Python
2. What is the result of 7 // 2 in Python?
Getting Started with Python
3. Which symbol starts a comment?
Variables and Data Types
4. What does type(3.0) return?
Variables and Data Types
5. Which expression correctly turns the string "12" into a number?
Variables and Data Types
6. Which variable name is valid in Python?
Operators and Expressions
7. What is the value of 2 + 3 * 4 ** 2?
Operators and Expressions
8. Which of these values is truthy?
Operators and Expressions
9. What does count += 4 do?
Control Flow: if, elif, else
10. How does Python define a block of code?
Control Flow: if, elif, else
11. In an if/elif/elif/else chain, how many branches execute?
Control Flow: if, elif, else
12. Which is the correct way to check for None?
Loops: for and while
13. How many numbers does range(2, 11, 3) produce?
Loops: for and while
14. What does the continue statement do?
Loops: for and while
15. When does a for ... else block run?
Lists, Tuples, Sets and Dictionaries
16. What does letters[1:4] return for a list of five items?
Lists, Tuples, Sets and Dictionaries
17. Which collection stores unique values with no order?
Lists, Tuples, Sets and Dictionaries
18. How do you safely read a possibly missing dictionary key?
Functions and Scope
19. What does a function return if it has no return statement?
Functions and Scope
20. What does *args collect in a function signature?
Functions and Scope
21. Why is def f(x, bag=[]) risky?
Strings, Input and Files
22. What type does input() always return?
Strings, Input and Files
23. What does text.replace("a", "b") do to the original string?
Strings, Input and Files
24. Why use with open(...) as f?
Errors, Exceptions and Debugging
25. Which exception does int("hello") raise?
Errors, Exceptions and Debugging
26. Which block always runs, exception or not?
Errors, Exceptions and Debugging
27. Why should you avoid a bare except:?
Modules, Classes and Next Steps
28. What is a Python module?
Modules, Classes and Next Steps
29. What is the role of __init__ in a class?
Modules, Classes and Next Steps
30. Why use a virtual environment?