Module 1: Collections: List, Tuples, Set Flashcards
_________ is a built-in python module that provides useful container datatypes.
Collections
_________ datatypes allow us to store and access values in a convenient way.
Container
_________ in Python are containers that are used to store collections of data, for example, list, dict, set, tuple etc. and they are under the built-in collections.
Collections
a collection which is ordered and changeable, are written with square [ ] brackets
List
In list, index starts with 1, items are separated with comma
True or False
F
index starts with 0, items are separated with comma
lists include double quotation if the item is string
True or False
T
The syntax below belongs to the ________ collection:
var_name = [ , , , ….]
List
Samlist = [“sun”, “moon”,”star”,”cloud”] -> string values
The index of “moon” is _______
1
access the list items by referring to the _______ number
index
Samlist = [5,8,2,5,4] –> are ________ values
non-string
Samlist = [“sun”, “moon”,”star”,”cloud”] -> are _______ values
string
You can access list items by referring to the ________
index number
item
key
value
index number
What is the output of the list example below?
Samlist = [“sun”, “moon”,”star”,”cloud”]
print(Samlist [2])
[“star”]
What is the output of the list example below?
Samlist = [5,8,2,5,4]
print(Samlist[3])
[6]
in ________ you need to specify the range of indexes by specifying where to start and where to end the range. The return value will be a new list in the specified items
accessing range of items
Access range of items syntax:
print (var_list[start_index : end_index])
What is the output of the list example below?
Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[2:6])
[2,6,4,1]
What is the output of the list example below?
Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[0:2])
[5,8]
accessing range of items without a start or end index. syntax:
print (var_list[: end_index])
start with index 0
In the syntax:
print (var_list[: end_index])
the range will go on to the ______ of the list
end
What is the output of the list example below?
Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[:4])
[5,8,2,6]
What is the output of the list example below?
Samlist = [5,8,2,6,4,1,3,7,9]
print(Samlist[5:])
[1,3,7,9]
means beginning from the end, means -1 refers to the last item of the list, -2 refers to the second last item and so on.
Negative indexing
______ of negative indexing needs to specify the negative indexes if you want to start the search form the of the list.
Range