[Hint: Definition]
The append() method
What is ... "adds an element at the end of the list"?
[Source: W3Schools]
[Hint: Definition]
The pop() method
What is ... "removes the element at the specified position" (by default, the last item)?
[Source: W3Schools]
To clear a list
What is ... use the clear() method?
# Hint: The coding concept
my_list = []
What is ... the empty list?
[Hint: Definition]
OOP
What is ... Object-Oriented Programming?
[Hint: Definition]
The sort() method
What is ... the list method that "sorts the list (ascending by default)"?
[Source: W3Schools]
[Hint: Definition]
The remove() method
What is ... "removes the first occurrence of the element with the specified value"?
[Source: W3Schools]
# Hint: The coding concept
a = []
b = a.copy()
What is ... how do you create a copy of a list?
Or how do you create a copy of a list?
What is ... "a function and not a method"?
Factory is to car as _____ is to _____.
Blueprint is to bridge as _____ is to _____.
What is ... class is to object?
To make the list method sort() sort in descending order
What is ... reverse = True?
# Hint: The output
list = ['apple', 'banana', 'carrots']
list.pop(2)
print(list)
What is ... apple, banana?
[FYI: The code was tested with PythonTutor.]
Lists are important because ...
What is ... lists can store multiple data items of the same data type (or different data types) that are related?
# Hint: The output
my_list = ["bat", "cat", "hat"]
print(my_list[3])
What is ... the IndexError?
[FYI: The code was tested with PythonTutor.]
Is like a function but is not a function
What is ... a method?
To sort strings in a list from biggest to smallest lengths
What is ... specify (key=len, reverse = True)?
# Hint: The Output
list = ['apple', 'banana', 'carrots']
list.remove(1)
print(list)
What is ... the ValueError?
[FYI: The code was tested with PythonTutor.]
# Hint: Not the output
my_string = "!skcor nuH .rM"
my_string = my_string[::-1]
print(my_string)
What is ... the "secret formula" to reverse a string (in Python)?
Or how do you reverse a string (in Python)?
# Hint: The output
my_list = ["bat", "cat", "hat"]
print(my_list[-1])
What is ... hat?
Or what is ... the last item (in the list)?
Or what is ... negative indexing?
[FYI: The code was tested with PythonTutor.]
[Hint: Keyword]
class
What is ... the (Python) keyword used to define (or to create) a class?
# Hint: The output
list = ['apple', 'banana', 'carrots']
list.append('celery')
list.sort(key = len, reverse = True)
print(list)
What is ... carrots, banana, celery, apple?
[FYI: The code was tested with PythonTutor.]
# Hint: The output
list = ['apple', 'banana', 'carrots', 'mango', 'pear']
list.remove('apple')
list.pop(3)
print(list)
What is ... banana, carrots, mango?
[FYI: The code was tested with PythonTutor.]
# Hint: Not the output. What the code does.
my_list = ["Lenny", "Joey", "Danny"]
if "Lenny" in my_list:
print("'Lenny' is in the list")
What is ... how to check if an item (or element) is in a list?
[FYI: The code was tested with PythonTutor.]
# Hint: The output
my_string = "Eggs, spam, ham, beans"
my_string.reverse()
print(my_string)
What is ... the AttributeError?
Or what is ... "Python has no built-in string reverse() function or method"?
[FYI: The code was tested with PythonTutor.]
[Hint: Definition] self
What is ... the parameter that refers to the instance (or object) calling the method?