1/187
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Python typing: static or dynamic?
Dynamic. You don't declare variable types, and they're checked at runtime
How does Python mark code blocks?
Indentation plus a colon (Java uses { })
Python single-line vs multi-line comment
Is Python compiled or interpreted?
Interpreted
Year Python was first released
1991
range(3, 10) produces what?
3, 4, 5, 6, 7, 8, 9 (stop is excluded)
range(17, 100, 2) means what?
Start at 17, stop before 100, step 2 (odd numbers)
Slice syntax
seq[start:end:step]. Start is inclusive, end is exclusive, default step is 1
s = "Python": s[-1], s[0:4], s[::2]
'n', 'Pyth', 'Pto'
How do you reverse a string or list?
[::-1]
my_list[-2::-1] on [10,20,30,40,50,60]
[50, 40, 30, 20, 10] (start at 2nd-last, go backwards)
my_list[:3] vs my_list[2:]
First 3 elements (indices 0-2) vs everything from index 2 onward
Are strings mutable?
No, immutable. Methods return a new string
"a,b,c".split(",") and "-".join(parts)
['a','b','c'] and 'a-b-c'
s.find("x") when "x" isn't found
Returns -1
"ab" * 3
'ababab'
List: mutable or immutable? Ordered?
Mutable, ordered
list.append(x) vs list.insert(i, x)
Adds to the end vs inserts at index i
list.sort() vs sorted(list)
Sorts in place (returns None) vs returns a new sorted list
b = a (a is a list): does it copy?
No. Both names point to the same list. Use a.copy()
How do you access element in row 2, column 1 of a list of lists?
matrix[2][1] (first index = sublist, second = element)
Access the red value of an RGB image pixel
image[row][column][color]
pop() vs remove(x)
pop() removes and returns the last item (or by index). remove(x) removes the first matching value