Python Basics: Syntax & Core Concepts
by FlashQuest
50 Python flashcards on beginner syntax and core concepts. The first group covers data types (int, float, str, bool, list, tuple, dict, set, None) and operators like **, // and %. Next come control flow with if, elif, else, for, while, break and continue. Functions follow, with def, return, default arguments, *args, **kwargs and lambda. The deck then covers built-ins such as len(), range(), sorted(), enumerate() and zip(), string and list methods, list comprehensions, comments and indentation. Written from the official python.org documentation, and each card has an explanation.
After you install, search the Table for “Python Basics: Syntax & Core Concepts”.
All 50 cards in this deck.
Made by FlashQuest. Last updated October 2026.
- What Python type holds whole numbers?
- int
- Python integers have arbitrary precision, so they never overflow; they grow as large as memory allows. Example: 2 ** 100 gives an exact 31-digit result.
- What Python type holds decimal numbers?
- float
- Floats are 64-bit IEEE 754 binary numbers, so some decimals are inexact: 0.1 + 0.2 == 0.3 is False. Any literal with a decimal point, like 3.0, is this type.
- What Python type holds text?
- str
- Strings are sequences of Unicode characters, written in single, double or triple quotes. Example: name = 'Ada' creates one, and len(name) is 3.
- What Python type holds True or False?
- bool
- bool has exactly two values, True and False, and is a subclass of int, so True + True equals 2. Comparisons such as 3 > 2 return this type.
- What is a Python list?
- An ordered, changeable sequence
- Lists are written in square brackets and can be changed in place: items = [1, 2]; items.append(3). Order is kept and duplicates are allowed.
- What is a Python tuple?
- An ordered, unchangeable sequence
- Tuples are written with parentheses, or just commas: point = (3, 4). Once created, items cannot be replaced, which makes tuples usable as dict keys when their items are hashable.
- What is a Python dict?
- A collection of key-value pairs
- Dicts map keys to values: ages = {'Ana': 30}; ages['Ana'] returns 30. Keys must be hashable, and since Python 3.7 dicts keep insertion order.
- What is a Python set?
- Unordered collection of unique items
- Sets drop duplicates automatically: {1, 2, 2} is {1, 2}. They support fast membership tests and math operations like union (|) and intersection (&), but not indexing.
- What does the None value represent?
- The absence of a value
- None is Python's single null object, of type NoneType. Check for it with identity, as in if x is None:, rather than ==.
- Are Python strings mutable?
- No, they are immutable
- Any change creates a new string: s = 'cat'; s[0] = 'b' raises TypeError. Methods like s.upper() return a new string and leave s untouched.
- What operator raises a number to a power?
- ** (double asterisk)
- 2 ** 3 gives 8, and pow(2, 3) does the same. It binds tighter than unary minus on its left, so -2 ** 2 is -4, and it groups right to left: 2 ** 3 ** 2 is 512.
- What does the // operator do?
- Floor division (rounds down)
- // divides and rounds down toward negative infinity: 7 // 2 is 3 and -7 // 2 is -4. With a float operand the result is a float, so 7.0 // 2 is 3.0.
Show the other 38 cards
-
What does the % operator return?
The remainder
% gives what is left after division: 7 % 3 is 1. A common use is testing evenness with n % 2 == 0. The result takes the sign of the divisor, so -7 % 3 is 2.
-
What does the == operator check?
Equality of values
== compares values, while 'is' checks whether two names point to the same object. Example: [1, 2] == [1, 2] is True, but [1, 2] is [1, 2] is False.
-
What does the 'and' operator require?
Both sides are true
'and' short-circuits: if the left side is falsy, Python returns it without evaluating the right. Example: x > 0 and x < 10 is True only when x is between them.
-
What does the 'or' operator require?
At least one side is true
'or' returns the first truthy operand, or the last one if none are truthy. That enables defaults: name = user_input or 'Guest'.
-
What does the 'in' operator check?
Membership in a collection
'in' tests whether a value is contained in a list, tuple, string, set or dict, which is why the answer says collection, not sequence. Example: 'a' in 'cat' is True, and for a dict, 'in' checks the keys.
-
What keyword starts a conditional?
if
An if statement runs its indented block only when the condition is truthy, and the line ends with a colon. Example: if age >= 18: print('adult').
-
What keyword handles an alternative condition?
elif
elif is short for 'else if' and is checked only when the earlier conditions were false. You can chain as many as you need. Example: elif score >= 80: grade = 'B'.
-
What keyword runs when no condition matches?
else
else takes no condition and catches every case the if and elif tests missed. It can also follow for, while and try blocks. Example: else: print('no match').
-
What keyword loops over a sequence?
for
Python's for loop iterates directly over items rather than counting an index. Example: for name in ['Ana', 'Bo']: print(name). Use range() when you need numbers.
-
What keyword loops while a condition is true?
while
A while loop repeats as long as its condition stays truthy, so something in the body must eventually make it false. Example: while n > 0: n -= 1.
-
What does the break statement do?
Exits the loop immediately
break ends the innermost for or while loop at once and skips any else clause on that loop. Example: inside for x in data:, the line if x < 0: break stops at the first negative.
-
What does the continue statement do?
Skips to the next iteration
continue skips the rest of the current loop body and jumps to the next iteration. Example: inside for x in data:, the line if x < 0: continue skips negatives but keeps looping.
-
What keyword defines a function?
def
def is followed by the function name, parentheses and a colon, then an indented body. Example: def greet(name): return 'Hi ' + name.
-
What statement sends a value out of a function?
return
return ends the function and hands a value back to the caller; return a, b sends back a tuple. Example: def square(x): return x * x.
-
What is a default argument?
A parameter with a preset value
In def greet(name='friend'):, calling greet() uses 'friend'. Defaults are evaluated once at definition time, so never use a mutable default like [] for a parameter.
-
What does *args collect?
Extra positional arguments
*args gathers any extra positional arguments into a tuple. Example: def total(*args): return sum(args), so total(1, 2, 3) returns 6. The name args is only a convention.
-
What does **kwargs collect?
Extra keyword arguments
**kwargs gathers extra name=value arguments into a dict. Example: def show(**kwargs): print(kwargs) prints {'a': 1} for show(a=1). The name kwargs is only a convention.
-
What does a function return with no return statement?
None
A function that ends without return, or with a bare return, gives back None. Example: result = print('hi') sets result to None.
-
What keyword creates a small anonymous function?
lambda
lambda builds a one-expression function inline: square = lambda n: n * n. It is often passed to functions like sorted(items, key=lambda p: p[1]).
-
What does len() return?
The number of items in an object
len() works on strings, lists, tuples, dicts and sets. Example: len('hello') is 5 and len({'a': 1}) is 1. For a dict it counts keys.
-
What does range(5) produce?
Numbers 0 through 4
range(5) is a lazy sequence of 0, 1, 2, 3, 4: it starts at 0 and stops before 5. list(range(5)) gives [0, 1, 2, 3, 4].
-
What does print() do?
Displays output to the screen
print() writes its arguments to standard output, separated by spaces and followed by a newline. Example: print('a', 'b', sep='-') shows a-b.
-
What does type() return?
The type of an object
type() returns the class of its argument. Example: type(3.0) returns <class 'float'>. To check a type, isinstance(x, float) is usually preferred.
-
What does input() return?
A string from the user
input() always returns text, even when the user types digits, so convert it: age = int(input('Age: ')). The optional argument is shown as a prompt.
-
What does int('7') return?
The integer 7
int() converts a numeric string to an integer, so int('7') + 1 is 8. A string that is not a whole number, such as int('7.5'), raises ValueError.
-
What does str(7) return?
The string '7'
str() converts any object to its text form, so str(7) + 'th' gives '7th'. Without it, 7 + 'th' raises TypeError.
-
What does sorted() return?
A new sorted list
sorted() accepts any iterable and returns a fresh list, leaving the original unchanged. Compare list.sort(), which sorts in place and returns None. Example: sorted('cba') gives ['a', 'b', 'c'].
-
What does sum([1, 2, 3]) return?
6
sum() adds every item of an iterable of numbers: 1 + 2 + 3. An optional start value is added too, so sum([1, 2, 3], 10) gives 16.
-
What does enumerate() add to items?
An index counter
enumerate() yields (index, item) pairs, starting at 0 by default. Example: for i, name in enumerate(names, start=1): print(i, name).
-
What does zip() do?
Pairs items from multiple iterables
zip() yields tuples combining items at the same position: list(zip([1, 2], ['a', 'b'])) gives [(1, 'a'), (2, 'b')]. It stops at the shortest input; pass strict=True to raise ValueError on unequal lengths instead.
-
What does list.append(x) do?
Adds x to the end of the list
append() changes the list in place and returns None. Example: nums = [1, 2]; nums.append(3) makes [1, 2, 3]. To add several items at once, use extend().
-
What does str.split() do?
Splits a string into a list
With no argument, split() breaks on runs of whitespace; with one, it breaks on that separator. Example: 'a,b,c'.split(',') gives ['a', 'b', 'c'].
-
What does '-'.join(list) do?
Joins items into one string
join() is a string method: the string it is called on goes between the items. Example: '-'.join(['a', 'b', 'c']) gives 'a-b-c'. Every item must already be a string.
-
What does str.strip() do?
Removes surrounding whitespace
strip() returns a copy without leading and trailing spaces, tabs and newlines; lstrip() and rstrip() trim one side. Example: ' hi\n'.strip() gives 'hi'.
-
What is a list comprehension?
A compact way to build a list
A list comprehension puts a loop inside square brackets: [x * x for x in range(5)] gives [0, 1, 4, 9, 16]. An optional if filters items: [x for x in data if x > 0].
-
What is an empty list's truth value?
False
Empty containers are falsy, so if items: runs only when the list has something in it. The same goes for '', {}, set(), 0 and None.
-
What symbol starts a single-line comment?
# (hash sign)
Python ignores everything from # to the end of the line. Example: x = 5 # starting value. Triple-quoted strings are string literals, not comments, though they often serve as docstrings.
-
What defines a code block in Python?
Indentation
Python uses indentation instead of braces to group statements; PEP 8 recommends 4 spaces per level. Mixing tabs and spaces inconsistently raises TabError.
Every card is here to read. Study them in the app, with spaced repetition bringing back the ones you miss.
Study it properly.
All 50 cards are in the app, scheduled so the ones you miss come back sooner.