Lesson 02
Question Bank
Answer extra Python questions on types, flow, functions, files, classes, patterns, threads, sockets, and database queries.
Answer extra Python questions on types, flow, functions, files, classes, patterns, threads, sockets, and database queries.
Example
checks = []
checks.append(type([]) is list)
checks.append(type(()) is tuple)
left = []
right = []
checks.append(left == right)
checks.append(left is right)
print(checks)The list is [True, True, True, False]. An empty list equals another empty list, and they are not the same object. The questions on this page are extra revision. They sit beside the lesson quizzes you already took. Say the answer before you open it.
Extra questions
What does a break do inside a loop?
It leaves that loop. Later lines in the loop do not run. Code after the loop still runs.
What does continue do?
It skips the rest of this pass and starts the next pass of the same loop.
Why is a bare except a weak choice?
It also catches exits you usually want to see, such as KeyboardInterrupt. Name the error you can handle, and put the specific type before a broader one.
What does a function return when it has no return statement?
None.
What is the difference between append and extend on a list?
append adds one item. extend adds each item from another sequence.
When does a with block close a file?
When the block ends, including when the block raises.
What does super() call in an overriding method?
The parent version of that method, so the child can add work without copying the parent body.
What does a raw string change in a pattern?
Backslashes stay for the pattern. A normal string would treat some of them as text escapes.
Key takeaways
-
Answer first, then compare
-
==compares values, andiscompares identity -
A missing
returngivesNone -
Next: Interview Tips — definition, example, then the pitfall
-
Previous: Practice List
Loading playground…
Check your understanding
Question Bank Quiz
Two empty lists compare equal with ==. What does is report?
1 / 10