GUIDE深度 · Deep dive

List and Dict Output: Slices, Comprehensions, get

For lists, check index and slice bounds: [1:4] takes 1, 2, 3; a negative step reverses. For dicts, check whether the key exists: d[k] raises if missing, d.get(k) returns None. For comprehensions, read the expression first, then the condition.

更新 2026-10-30 · 公式可核验

Slicing

[start:stop:step]; stop is excluded.

[::-1] reverses.

Dicts

keys()/values()/items() return views; list() converts them.

get(k, default) does not raise.

FAQ

Comprehension order?

for first, then if, then the expression.

Are dicts ordered?

Python 3.7+ preserves insertion order.

Sources

Related calculators

Python Output: 1000 Gamified Expression and Method Cards1000 Python output cards covering arithmetic, strings, lists, dicts, comprehensions and built-ins, in 50 levels with spaced repetition.

More guides

Hiragana vs KatakanaRead guideSpaced Repetition and the Forgetting CurveRead guideOn Readings vs Kun ReadingsRead guideAn N5 Kanji Study OrderRead guide