Checkpoint: Core Syntax
A checkpoint is a consolidation lesson that combines everything you've just learned — slicing, truthiness, None, ternaries, the walrus, match/case, unpacking, and sorting — into one realistic build.
Learn Checkpoint: Core Syntax in our free Python course — an interactive lesson with runnable examples, a practice exercise and a quick reference.
Part of the free Python course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
No new syntax here. Instead you'll recap the toolkit, write a small program that parses and ranks records using these features together, and check your understanding with a short quiz.
Before the big challenge, here's a quick tour that fires each concept once. Read it, predict the output, then run it:
You're given raw rows of player data. Build a small pipeline that:
Answer each from memory, then expand to check. A wrong answer points you to the lesson to revisit.
1. What does "python"[::-1] produce, and what does [::-1] mean?
'nohtyp' . A step of -1 with both bounds omitted returns a reversed copy of the whole sequence. (Lesson: Slicing)
2. Which of these are falsy: 0 , "0" , [] , [0] , None ?
0 , [] , and None are falsy. "0" (non-empty string) and [0] (non-empty list) are truthy. (Lesson: Booleans & Truthiness)
None is a unique singleton, so identity ( is ) is correct, fast, and can't be fooled by a class that overrides == . It's the PEP 8 recommendation. (Lesson: None & NoneType)
4. Rewrite this as a ternary: if t >= 25: label = "hot" else: label = "mild" .
label = "hot" if t >= 25 else "mild" — value first, condition, then fallback. (Lesson: Ternary)
5. In first, *rest = [1, 2, 3, 4] , what is rest and what type is it?
rest is [2, 3, 4] , and a starred target is always a list (even from a tuple). (Lesson: Unpacking)
6. How do you sort records by score descending, then name ascending?
Use a tuple key that negates the number: sorted(items, key=lambda p: (-p.score, p.name)) . Python's stable sort keeps the tie-break order. (Lesson: Sorting)
Checkpoint cleared — your core syntax is solid!
You combined slicing, truthiness, None, ternaries, the walrus, match/case, unpacking, and sorting into a working pipeline, and proved your recall on the quiz. This toolkit is the backbone of everyday Python.
🚀 Up next: functools — lru_cache, partial, reduce — powerful tools for caching, pre-filling arguments, and folding sequences.
Practice quiz
What does "python"[::-1] produce?
- "python"
- "nohty"
- "nohtyp"
- an error
Answer: "nohtyp". A slice with step -1 and both bounds omitted returns a reversed copy of the whole sequence, so "python" becomes "nohtyp".
Which of these values is truthy?
- "0"
- 0
Answer: "0". The string "0" is non-empty, so it is truthy. 0, [] (empty list), and None are all falsy.
Why prefer x is None over x == None?
- is None is shorter to type
- == None raises a SyntaxError
- They behave differently for integers only
- None is a unique singleton, so identity is correct, fast, and cannot be fooled by a custom __eq__
Answer: None is a unique singleton, so identity is correct, fast, and cannot be fooled by a custom __eq__. None is a single, unique object, so the identity check is is None is the correct and PEP 8 recommended way to test for it.
What is the ternary form of: if t >= 25: label = "hot" else: label = "mild"?
- label = if t >= 25 "hot" else "mild"
- label = "hot" if t >= 25 else "mild"
- label = t >= 25 ? "hot" : "mild"
- label = "mild" if t >= 25 else "hot"
Answer: label = "hot" if t >= 25 else "mild". Python's conditional expression puts the value first: value_if_true if condition else value_if_false.
In first, *rest = [1, 2, 3, 4], what is rest?
A starred target captures the remaining items, and it is always a list — here [2, 3, 4] — even when unpacking a tuple.
What does the walrus operator := do?
- Compares two values for equality
- Defines a lambda
- Assigns a value and returns it as part of an expression
- Performs floor division
Answer: Assigns a value and returns it as part of an expression. The walrus operator assigns to a name and also returns the value, letting you assign inside conditions and comprehensions.
In a match statement, what does the case _ pattern do?
- Matches only the value None
- Acts as a wildcard that matches anything (the default branch)
- Matches an empty sequence
- Raises an error if reached
Answer: Acts as a wildcard that matches anything (the default branch). The underscore is the wildcard pattern: it matches any value and is typically the final, catch-all case.
How do you sort records by score descending, then name ascending?
- sorted(items, key=lambda p: (p.score, p.name))
- sorted(items, reverse=True)
- sorted(items, key=lambda p: p.name, reverse=True)
- sorted(items, key=lambda p: (-p.score, p.name))
Answer: sorted(items, key=lambda p: (-p.score, p.name)). Negating the number makes it sort descending while name stays ascending; the tuple key combines both, and the sort is stable.
What is the difference between sorted(x) and x.sort()?
- They are identical in every way
- sorted() returns a new list; .sort() sorts the list in place and returns None
- .sort() returns a new list; sorted() mutates in place
- sorted() only works on tuples
Answer: sorted() returns a new list; .sort() sorts the list in place and returns None. sorted() builds and returns a new sorted list, leaving the original untouched, while list.sort() reorders the list in place and returns None.
What does the expression "" or "default" evaluate to?
- ""
- True
- "default"
- None
Answer: "default". or returns the first truthy operand; "" is falsy, so the expression yields the second operand, "default".