1/32
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
What does dynamically typed mean
Python is dynamically typed — types are determined at runtime, not declared in advance
Is python interpreted or translated
Python source code is executed line by line by an interpreter.
What paradigms does python support
Procedural, object oriented and functional styles
What is a REPL
Read - eval - print loop
Interactive interpreter where you type and run code one line at a time
What is semantic whitespace
indentation that defines code structure
What does python use instead of braces
Indentation
What does python use instead of semicolons
Nothing — statements end at the line break
How do you write a comment in python
# comment herehow do you find the type of a variable in python
type(x)
How is boolean true and false written in python
True and False
How do you cast data types in python
int(“5)
float(3)
str(42)
list(“abc”)
How do you create a list in python
empty = []
numbers = [1, 2, 3, 4, 5]
mixed = [1, "two", 2, 3.24, True, None]
nested = [[1, 2], [3, 4]]how do you add items to a list in python
lst.append(x)
how do you insert items into a list
lst.insert(i, x)
i for index
x for data
how do you remove items from a list in python
list.remove(x)
removes first instance of x
How do you get the length of the list
len(lst)
how do you check if an item is in a list in python
x in lst
What is a tuple in python
A list that cannot be changed (immutable)
basically a const list
How do you create a dictionary in python
empty = {}
person = {"name": "Alice", "age": 30}
# like a list but with namesWhat is a set in python
An unordered collection of unique items
removes duplicates
has no order
How do you get the length of a string in python
len(string)
what actions can you perform on a string
s.upper()
s.lower()
s.strip() — removes leading / tailing whitespace
what does s.split(“,”) do
splits the data in the string (s), based on the identification of the delimiter (“,”). returns in a list
How can you concatenate with strings and variables
greeting = f"Hello, {name}"what does an if statement look like in python
if score >= 70:
grade = "distinction"
elif score >= 50:
grade = "pass"
else:
grade = "fail"what does a while loop look like in python
while count < 10:
print(count)
count += 1what does a for loop look like in python
for i in range(10):
print(i)what does loop control contain in python
break — exit loop
continue — skip to next iteration
how do you define a function in python
def add(a, b):
return a + b
result = add(3, 5);how do you define a class in python
class Car:
def __init__(self, colour):
self.colour = colour
self.miles_driven = 0
def drive(self, miles):
self.miles_driven += miles
def get_colour(self):
return self.colourhow do you create an object in python
c = Car("white")
c.drive(100);how does inheritance work in python
class Mammal:
def __init__(self, name):
self.name = name
class Person(Mammal):
def __init__(self, name, age):
super().__init__(name)
self.age = ageHow does exception handling work in python
try:
x = int(input("Enter a number:"))
y = 10 / x
print(y)
except ValueError:
print("That wasn't a number")
except ZeroDivisonError:
print("Can't divide by zero")
except Exception as e:
prin("Error: {e}")