Summary of Key Concepts for Your Python Exam
This cheat sheet provides a solid overview of core Python syntax and data
structures. You should aim to understand how to use each of these
concepts and what their typical output will be.
1. Variables and Data Types (The Building Blocks)
● Declaration & Assignment:
○ Assigning single values (myVar = 5).
○ Assigning return values from functions (myVar = myFunction()).
○ Multiple variable assignment on one line (var1, var2, var3 = 1, 2, 3).
● Fundamental Data Types:
○ Integers (int): Whole numbers (e.g., 12).
○ Floats (float): Numbers with decimal points (e.g., 12.0).
○ Strings (str):): Text enclosed in single or double quotes (e.g.,
"twelve", '12').
○ Booleans (bool): True or False.
● Type Operations:
○ type(): Check the data type of a variable.
○ Type Conversion (Casting): int(), float(), str(). Understand how
these convert between types (e.g., int(12.0) becomes 12, float(12)
becomes 12.0).
○ round(): Rounds a float to the nearest whole number.
○ print(): Display output to the console.
2. Operators (How to Manipulate Data)
● Arithmetic Operators:
○ + (addition), - (subtraction), * (multiplication), / (division - always float
result).
○ // (Floor Division): Get the whole number result of division (e.g., 2.1 //
2 is 1.0, 5 // 2 is 2). Crucial to understand.
○ % (Modulo): Get the remainder of a division (e.g., 5 % 2 is 1). Pairs
with floor division.
○ ** (Exponentiation/Power of).
● Assignment/Reassignment Operators:
○ = (simple assignment).
○ +=, -=, *=, /=: Shorthand for performing an operation and assigning
the result back to the variable (e.g., myNum += 5 is myNum =
myNum + 5).
● Comparison Operators (For Conditional Logic):
, ○ < (less than), > (greater than), <= (less than or equal to), >=
(greater than or equal to).
○ == (equal to), != (not equal to).
○ These always result in a Boolean (True or False) value.
3. Strings (Working with Text)
● Basic Properties:
○ len(): Get the length of a string.
○ Slicing: Extract parts of a string using [start:end] (e.g., name[0:4]).
Remember end is exclusive.
● Key String Methods:
○ .title(): Capitalizes the first letter of each word.
○ .islower(): Checks if all characters are lowercase.
○ .count('substring'): Counts occurrences of a substring.
○ .format() (and implicitly f-strings, though not explicitly shown):
Format strings by inserting values into placeholders (e.g., "Welcome
to {}, {}.".format(code, username)). Very important for output.
○ .split("delimiter"): Splits a string into a list of substrings based on a
delimiter (e.g., myPhrase.split(" ")).
4. Functions (Reusable Code Blocks)
● Definition: def function_name(parameter1, parameter2):
● Input (Parameters/Arguments): Values passed into the function.
● Output (Return Value): Use return to send a value back from the
function. If no return, the function implicitly returns None.
● Calling: Execute a function by its name with arguments (e.g., myArea =
areaOf(4,6)).
5. Control Flow (Making Decisions and Repetitions)
● If / Elif / Else Statements (Decision Making):
○ if condition:: Executes if the condition is True.
○ elif condition:: An alternative condition if the preceding if/elif were
False.
○ else:: Executes if all preceding if/elif conditions were False.
○ Indentation is critical for defining blocks of code.
● Boolean Operations (and, or, not):
○ and: True only if both sides are True.
○ or: True if at least one side is True.
○ not: Reverses the Boolean value (not True is False, not False is True).
● For Loops (Iterating through collections):
This cheat sheet provides a solid overview of core Python syntax and data
structures. You should aim to understand how to use each of these
concepts and what their typical output will be.
1. Variables and Data Types (The Building Blocks)
● Declaration & Assignment:
○ Assigning single values (myVar = 5).
○ Assigning return values from functions (myVar = myFunction()).
○ Multiple variable assignment on one line (var1, var2, var3 = 1, 2, 3).
● Fundamental Data Types:
○ Integers (int): Whole numbers (e.g., 12).
○ Floats (float): Numbers with decimal points (e.g., 12.0).
○ Strings (str):): Text enclosed in single or double quotes (e.g.,
"twelve", '12').
○ Booleans (bool): True or False.
● Type Operations:
○ type(): Check the data type of a variable.
○ Type Conversion (Casting): int(), float(), str(). Understand how
these convert between types (e.g., int(12.0) becomes 12, float(12)
becomes 12.0).
○ round(): Rounds a float to the nearest whole number.
○ print(): Display output to the console.
2. Operators (How to Manipulate Data)
● Arithmetic Operators:
○ + (addition), - (subtraction), * (multiplication), / (division - always float
result).
○ // (Floor Division): Get the whole number result of division (e.g., 2.1 //
2 is 1.0, 5 // 2 is 2). Crucial to understand.
○ % (Modulo): Get the remainder of a division (e.g., 5 % 2 is 1). Pairs
with floor division.
○ ** (Exponentiation/Power of).
● Assignment/Reassignment Operators:
○ = (simple assignment).
○ +=, -=, *=, /=: Shorthand for performing an operation and assigning
the result back to the variable (e.g., myNum += 5 is myNum =
myNum + 5).
● Comparison Operators (For Conditional Logic):
, ○ < (less than), > (greater than), <= (less than or equal to), >=
(greater than or equal to).
○ == (equal to), != (not equal to).
○ These always result in a Boolean (True or False) value.
3. Strings (Working with Text)
● Basic Properties:
○ len(): Get the length of a string.
○ Slicing: Extract parts of a string using [start:end] (e.g., name[0:4]).
Remember end is exclusive.
● Key String Methods:
○ .title(): Capitalizes the first letter of each word.
○ .islower(): Checks if all characters are lowercase.
○ .count('substring'): Counts occurrences of a substring.
○ .format() (and implicitly f-strings, though not explicitly shown):
Format strings by inserting values into placeholders (e.g., "Welcome
to {}, {}.".format(code, username)). Very important for output.
○ .split("delimiter"): Splits a string into a list of substrings based on a
delimiter (e.g., myPhrase.split(" ")).
4. Functions (Reusable Code Blocks)
● Definition: def function_name(parameter1, parameter2):
● Input (Parameters/Arguments): Values passed into the function.
● Output (Return Value): Use return to send a value back from the
function. If no return, the function implicitly returns None.
● Calling: Execute a function by its name with arguments (e.g., myArea =
areaOf(4,6)).
5. Control Flow (Making Decisions and Repetitions)
● If / Elif / Else Statements (Decision Making):
○ if condition:: Executes if the condition is True.
○ elif condition:: An alternative condition if the preceding if/elif were
False.
○ else:: Executes if all preceding if/elif conditions were False.
○ Indentation is critical for defining blocks of code.
● Boolean Operations (and, or, not):
○ and: True only if both sides are True.
○ or: True if at least one side is True.
○ not: Reverses the Boolean value (not True is False, not False is True).
● For Loops (Iterating through collections):