Sequences#
What is the meaning of negative indices?
What is the meaning of
c1, c2, c3 = "bla"?
How does arithmetic work for sequences?
What is the meaning of
'y' in wordfor some stringword?
What is the meaning of
stepin a slice?
What is the result of
s[:i] + s[i:]for some sequences?
What is the length of
s[n:m]?
Is
(1) == (1,)?
When are tuples equal? When are they identical?
Can lists be an element of a list?
Which of the following types are
mutableand whichimmutable:float,string,list,tuple,dictionary,complex,integer?
Which of the following expressions are tuples and which are lists:
(1, 2, 3)[1, 2, 3][(1, 3), 'a', 45]
What is the difference between
squares + [36, 49]andsquares.extend([36, 49])?
Why is
a = [1, 2, 3]
b = a
a is b == True
but
a = [1, 2, 3]
b = [1, 2, 3]
a is b == False
Coding exercises#
Assign the string
'Python'to the variablewordand then extract the first 2 characters.
From the previously created variable
word, printthe last two characters
every second character
all characters, but in reversed order.
Try to build the string
"Gooooooooooooooooal"out of the string"Goal"
Create a list that contains three book titles
Create a list that consists of the squares of all numbers between 0 and 5. Then manipulate this list by doing the following
remove the last element of the list
set the second element to
2add three additional elements of your choice to the end of the list
add one element to the beginning of the list
print the number of elements that have a value of
0
Create a dictionary and fill it with content of your choice. Try out the methods available for dictionaries.
Assign the string
"Foo"to variables. Now try to change the first character ofstoP. Explain the error message you get.