bhylu.com

Advertisements

Python Quiz

Predict the behaviour of references, truthiness, and return values. Explain each answer before running the checks.

Understand the idea

Question 1: is the non-empty string False false in a condition? Question 2: does append return the updated list? Question 3: can a shallow copy share an inner list? Question 4: does a function with no return produce zero? The script exposes the first three directly; the fourth produces None, not zero.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

Your task

Predict the behaviour of references, truthiness, and return values. Explain each answer before running the checks.

Show the worked solution
Python

print(bool("False"))
items = []
print(items.append(1))
original = [[1]]
copied = original.copy()
print(original[0] is copied[0])

Check the result

The results are True, None, and True.

Test one more case

Write a separate check for an implicit function return and compare it explicitly with None.