In Python, tuples are enclosed in these types of brackets.
What are parentheses? ()
In Python, this line of code is used to create an empty list named myList.
What does this code do?
for num in range(5):
print(num)
It prints the numbers 0 through 4.
If you want to add an item to the end of a list called my_list, you would use this method.
What is append()?
This is the method that turns String
str = "I like pizza"
into the list
my_list = ["I", "like", "pizza"]
my_list = str.split()
?
This is a term in Computer Science that means that its elements cannot be changed after creation.
What is "immutable"?
Given the list my_list = [1, 2, 3], what will my_list[2] return?
What is 3?
This is the built-in Python function that can help you print the index and value of each item in a list using a for loop.
What is enumerate()?
This method is used to add all elements of one list to the end of another list.
What is extend()?
Given my_list = [ "eggs", "butter", "milk", "cheese"],
This is the output of
print ( my_list[-1] )
What is
cheese
?
Given the tuple t = (1, 2, 3), what will t[1] return?
What is 2?
Given the list my_list = [10, 20, 30], what would my_list[1:2] return?
What is [20]? (List from index 1 to 2, exclusive of 2. MUST INCLUDE BRACKETS OR INCORRECT)
Given the list numbers = [1, 2, 3, 4], how can you print each element using a regular for loop (without using "for i in range(x)"?
What is:
for num in numbers:
print(num)
This method deletes the first occurrence of a specified element from a list. If the element is not found, it raises a ValueError.
What is remove()?
This is the code you would want to write to get the number of Strings "jake" in the list
my_list = [ "jake", "finn", "jake", "BMO", "jake"]
What is
my_list.count("jake")
?
This is the ouput after the following code:
tup = (1, 2, 3)
tup[0] = 5
print(tup)
What is "No ouput. This operation will throw an error since we cannot modify an element of a tuple.
This list contains another list as one of its elements: list = [1, 2, [3, 4], 5]. To access the number 4, you would use this index.
What is list[2][1]?
Given the list numbers = [10, 20, 30], what will the following print?
for i, value in enumerate(numbers):
print(i, value)
This will print:
0 10
1 20
2 30
This is value of myList after the following:
myList = [7, a, 4, C]
myList = sort(myList)
What is " [4, 7, C, a] " ?
What will print given the below code?
my_list = [ "jump", "skip", "run"]
my_string = " then ".join(my_list)
my_new_list = my_string.split()
print (my_new_list)
What is
[ "jump", "then", "skip", "then", "run"]
This is how I would print the String "def" from the below tuple:
my_tuple = ( 1, 2, 3, ( "abc", "def", "ghi"), 4, 5)
What is " print my_tuple[3][1] "?
Given a list " my_list = ["Alina", "Bach", "Chen"] ", this is how you would turn this into a String "Alina and Bach and Chen" named "my_string" using a single method.
What is
my_string = " and ".join(my_list)
***Note the spaces on both sides of "and"!***
***BONUS DAILY DOUBLE - Worth an extra $500***
Given list_of_lists = [[1, 2], [3, 4], [5, 6]], this nested for loop would print each element one at a time.
What is:
for row in list_of_lists:
for item in row:
print(item)
This is how we transform the String
my_String = "apples bananas cranberries"
into the list my_list containing ["apples", "bananas", "cranberries"]
What is
my_list = list( my_String)
An iconic figure in the world of fashion, this French designer founded a renowned luxury brand that bears his name.
Who is Coco Chanel?