1/44
Vocabulary flashcards covering core Python signs, keywords, syntax symbols, list and random methods, and data types from the lecture notes.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
+
Add numbers, or join two strings ('a' + 'b' is 'ab').
–
Subtract.
*
Multiply, or repeat a string ('ab' * 3 is 'ababab').
/
Divide; always gives a decimal (7 / 2 is 3.5).
//
Divide and drop the remainder (7 // 2 is 3).
%
The remainder (7 % 2 is 1).
**
To the power of (3 ** 2 is 9).
=
Assign: store a value in a variable (x = 5).
==
Is equal to; compares two things and gives True or False.
!=
Is NOT equal to.
Less than.
>
Greater than.
Less than or equal to.
=
Greater than or equal to.
+=
Add to the variable (total += 2 means total = total + 2).
and
Both sides must be True.
or
At least one side must be True.
not
Flips True to False and False to True.
in
Is it inside? (3 in [1, 2, 3] is True).
def
Define a function.
return
Send a value back to where the function was called, and end the function.
Show something on the screen.
input()
Ask the user to type something; always gives back a string.
if
Run the indented code only when the condition is True.
elif
'Else if': checked only if the earlier conditions were False.
else
Runs when none of the earlier conditions were True.
for
Loop: repeat the indented code for each item.
range()
Makes a sequence of numbers; stops BEFORE the last number.
len()
How many items (or characters) there are.
import random
Load the random tools so you can use random.randint and others.
: (colon at the end of a line)
An indented block starts on the next line (after if, for, def).
Indentation
The indented lines belong to the if, for, or def above them.
[ ]
[1, 2, 3] makes a list; nums[0] gets the item at position 0.
-1 (in nums[-1])
The last item in the list.
( )
Function call: the inputs (print(5)); math: do this first; condition: group it.
f'…{x}…'
An f-string: puts the value of x into the text.
:.2f (inside an f-string)
Show the number as a decimal rounded to 2 places.
#
A comment; Python ignores the rest of the line.
append
Adds an item to the end of the list.
pop(i)
Removes the item at position i AND returns it.
insert(i, x)
Puts x at position i; the others shift right.
random.randint(a, b)
Gives a random whole number from a to b, including both ends.
random.choice(list)
Picks one item from the list at random.
int, float, str, and bool
int = whole number (5); float = decimal (5.0); str = text ('5'); bool = True or False.
int(), float(), and str()
Convert a value to that type (int(3.9) is 3; float(2) is 2.0; str(5) is '5').