1/28
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Integer (int)
A whole number without a decimal (e.g., 5, -23, 0).
int(15.9)
Results in 15. Casting to an int always truncates (chops off) the decimal.
Float
A number with a decimal (e.g., 5.0, 15.99, -2.3).
float(15.9)
Results in 15.9. Floats keep the decimal.
Standard Division (/)
Always results in a Float. 10 / 2 is 5.0.
Floor Division (//)
Divides and chops off the decimal (rounds down). 10 // 3 is 3.
Modulo (%)
Returns the remainder of a division. 10 % 3 is 1.
Type Error
Error occurring when you try to combine incompatible types (e.g., "age" + 21).
len()
Counts the characters (starts counting at 1)
len(“CS1315”)
Results in 6. It counts how many characters are in the string.
Index 0
The index of the first character in a Python string.
Index -1
The index of the last character in a Python string.
Slicing Syntax
string[start : stop : step]. Remember: stop is exclusive (not included).
“Python”[0:2]
Results in "Py". (Indices 0 and 1; 2 is excluded).
“Python”[::-1]
Results in "nohtyP". This is the standard trick to reverse a string.
.upper() / .lower()
String methods that return a copy of the string in all caps or all lowercase.
Assignment (=)
Used to set a variable to a value (e.g., x = 5).
Equality (==)
Used to compare if two things are equal (returns True or False).
Logical “and”
Evaluates to True only if both sides are true.
Logical “or”
Evaluates to True if at least one side is true.
“in” Operator
Checks if a substring exists within another string (e.g., 'a' in 'apple' is True).
“elif”
Short for "else if." It only checks this condition if the previous if was False.
The “Else” Rule
An else only runs if every if and elif above it was False. If one of them was True, Python skips the rest of the block.
While Loop Recipe
1. Initialize counter, 2. Check condition, 3. Update counter.
Infinite Loop
A loop that never ends because the condition never becomes False. (Usually missing i += 1).
Iteration
One complete execution of the block of code inside a loop.
Accumulator Pattern
Starting a variable at 0 or "" and adding to it inside a loop to build a final result.
Sentinel Condition
The condition that, once met, causes the loop to stop (e.g., while i < len(word):).
Casting (Conversions)
* int(“10“) turns a string into the number 10.
str(10) turns the number into the string “10”.
Trap: int(15.9) becomes 15. It doesn’t round; it just cuts the decimal off.