Programming flashcards

Python Basics: Syntax & Data Types

50 Python basics flashcards for syntax, collections, functions, files, exceptions, classes, typing, and virtual environments.

50 cards By @mazo
#python#basics#syntax#data-types#beginner
Study this deck free Browse Programming

About this deck

This 50-card Python basics deck builds a practical foundation from lists, dictionaries, loops, and functions through files, exceptions, generators, classes, type hints, and virtual environments.

Examples are short enough to type in a Python shell, making the deck useful as both recall practice and a guided coding checklist.

50cards
Python beginnerlevel
new Python programmers, students, and coding-course beginnersaudience

What you will learn

How to study this deck

Recommended study setup

Scope

This is a Python language starter deck. It does not cover a web framework, data science stack, packaging in depth, or advanced object models.

Review notes

Syntax and standard-library concepts checked against current Python 3 documentation on 2026-07-10.

All 50 cards in this deck

FrontBackStudy note
How do you write a comment in Python?Start the line with #.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is a list?An ordered, mutable collection: items = [1, 2, 3].Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is a tuple?An ordered, immutable collection: point = (2, 4).Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is a set?An unordered collection of unique items: s = {1, 2, 3}.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is a dictionary?A key-value collection: user = {"name": "Ana"}.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you define a function?Use def: def greet(name): return f"Hi {name}".Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What does len(items) return?The number of items in a collection.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is an f-string?A formatted string literal: f"Total: {price}".Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is indentation used for?It defines code blocks such as loops, functions, and conditionals.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you loop over a list?for item in items: ...Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you write an if/else?if x > 0: ... elif x == 0: ... else: ...Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is a list comprehension?A compact way to build a list: [x * 2 for x in items].Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What does range(5) produce?The numbers 0, 1, 2, 3, 4.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What does import do?It loads a module so you can use its code.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What is None?Python’s value for “no value” or “nothing here”.Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you convert a string to an int?Use int("42").Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
What are Python’s boolean values?True and False (capitalized).Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you handle errors?try: ... except SomeError: ...Practice cue: type a tiny example in a Python shell and predict both the value and its type before running it.
How do you assign a variable?Use name = value, for example count = 3.Python names do not need a type declaration before assignment.
What does type(value) return?The value’s runtime type.Examples include int, str, list, dict, and NoneType.
How do you create a multiline string?Use triple quotes: """text""" or three single quotes.Triple-quoted strings preserve line breaks.
What is slicing?Selecting a range with sequence[start:stop:step].The stop index is excluded; omitted bounds use the sequence ends.
What does items[-1] mean?The last item in a sequence.Negative indexes count backward from the end.
list.append(value)Adds one value to the end of a list.It mutates the list and returns None.
list.extend(values)Adds every item from an iterable to a list.Unlike append, it does not add the iterable as one nested item.
dict.get(key, default)Reads a key and returns a default instead of raising KeyError.Use indexing when a missing key should be treated as an error.
dict.items()Returns a view of key-value pairs.Common loop: for key, value in mapping.items():
Set intersectiona & b returns values present in both sets.Union uses | and difference uses -.
Iterable unpackingAssigns items to names: first, *rest = values.The starred target collects zero or more remaining items.
enumerate(items)Yields index-value pairs while iterating.Use enumerate(items, start=1) for one-based numbering.
zip(a, b)Pairs items from multiple iterables.Iteration stops at the shortest input unless strict=True is used to detect unequal lengths.
any(values)Returns True if at least one item is truthy.Returns False for an empty iterable.
all(values)Returns True if every item is truthy.Returns True for an empty iterable.
sorted(values)Returns a new sorted list from any iterable.list.sort() mutates a list in place instead.
lambdaCreates a small anonymous function containing one expression.Prefer def when the logic needs a name, statements, or documentation.
Generator expressionProduces values lazily: (x * 2 for x in items).Unlike a list comprehension, it does not build the whole list immediately.
yieldProduces a value from a generator function and pauses its state.Calling the function returns a generator iterator.
with open(path) as fileOpens a file and closes it automatically when the block ends.Specify encoding="utf-8" for predictable text handling.
raise SomeError("message")Raises an exception intentionally.Choose a specific exception type that explains the contract violation.
finallyRuns cleanup code whether or not an exception occurred.Context managers are often cleaner for files and locks.
How do you define a class?Use class Name: followed by attributes and methods.Class names conventionally use CapWords.
__init__Initializes a new instance after it is created.The first parameter is conventionally named self.
@dataclassGenerates common methods for classes that mainly store data.Import it from the standard-library dataclasses module.
Type hintAn annotation such as name: str or -> int.Hints support tools and readers but are not enforced automatically at runtime.
is versus ==is checks object identity; == checks value equality.Use is None and is not None for None checks.
in operatorTests membership in a collection or substring.Dictionary membership tests keys by default.
Truthy and falsy valuesEmpty containers, zero, None, and False are falsy.Custom objects are truthy unless they define otherwise.
match / caseMatches a value against structural patterns.It is more powerful than a simple switch because patterns can unpack data.
if __name__ == "__main__"Runs code only when the file is executed directly.Imported modules get their module name instead of "__main__".
python -m venv .venvCreates an isolated Python environment.Activate it before installing project-specific packages.

Frequently asked questions

Which Python version is this deck for?

It targets modern Python 3 syntax and concepts, including match/case, type hints, dataclasses, and virtual environments.

Does it include coding examples?

Yes. Many answers and notes contain minimal examples intended for the Python shell.

Is it enough to learn Python?

It is a recall foundation. Pair it with writing small programs, debugging, and one project that reads or transforms real data.

Is the Python Basics: Syntax & Data Types flashcard deck free?

Yes. You can study it free in your browser on MazoCards. Create a free account to save progress, track streaks, and sync across devices.

Git Commands Cheat Sheet

50 practical Git command flashcards for commits, branches, inspection, recovery, collaboration, and debugging history.

50 cards
Open

JavaScript Array Methods

50 JavaScript array method flashcards covering transformation, search, mutation, copying methods, iteration, and common pitfalls.

50 cards
Open

React Hooks Essentials

40 React 19.2 hook flashcards covering state, effects, refs, transitions, actions, external stores, common pitfalls, and when not to use a hook.

40 cards
Open

SQL Basics: Queries & Joins

50 SQL flashcards covering queries, filtering, joins, aggregation, subqueries, CTEs, windows, transactions, constraints, and query plans.

50 cards
Open

CSS Flexbox and Grid

CSS layout flashcards covering Flexbox, Grid, alignment, tracks, gaps, and responsive patterns.

41 cards
Open

Start studying Python Basics: Syntax & Data Types

Study these 50 cards free, then create an account to save your progress and build a streak.