ExercisesΒΆ
Create:
A tuple with two integers,
0and1.A tuple with two strings,
"a"and"tuple".A tuple with only one element,
"a tuple".Hint: you can either use the syntax presented at the beginning of the chapter, or use a list-tuple conversion.
A tuple with the integers between 0 and 99.
Hint: is there some way to exploit the
range()function?
Given
l = [0, 1, 2]andt = (0, 1, 2), what is the difference between:First case:
x = l x[0] = "ok"
Second case:
x = t x[0] = "ok"
Given the tuple:
tup = (0, 1, 2, [3, 4, 5], 6, 7, 8)
- What is the type of the first element of the tuple?
- What is the type of the fourth element?
- How many elements does the tuple contain?
- How many elements does the inner list contain?
- Change the last element of the inner list to
"last element". - Change the last element of the tuple to
"very last element". (Can you do that without resorting to tricks?)