Python Tuple Flashcards

 

card 1 of 22

 

3,1,"one"

 

tuple items are separated by commas

(3,1,'one')

card 2 of 22

 

("abc",3,True,"def",9.0,)

 

parentheses are preferred for tuples; an extra comma is permitted

('abc',3,True,'def',9.0)

card 3 of 22

 

type(3,4)

 

sometimes parentheses are necessary to avoid confusion

TypeError: type() takes 1 argument

card 4 of 22

 

type((3,4))

 

sometimes parentheses are necessary to avoid confusion

<type 'tuple'>

card 5 of 22

 

(True,(1,2,3),False)

 

tuples can contain tuples

(True,(1,2,3),False)

card 6 of 22

 

len((1,3,"abc",9))

 

the "length" of a tuples is the number of items in the tuple

4

card 7 of 22

 

len((3))

 

paretheses also mean function argument and evaluation order

TypeError: argument is not a string or tuple

card 8 of 22

 

len((3,))

 

extra comma avoids confusion (meaning a tuple)

1

card 9 of 22

 

type((3,))

 

extra comma avoids confusion (meaning a tuple)

<type 'tuple'>

card 10 of 22

 

type(())

 

the "empty" tuple is special

<type 'tuple'>

card 11 of 22

 

len(())

 

the "empty" tuple is special

0

card 12 of 22

 

(1+2,True and False)

 

expressions are evaluated first

(3,False)

card 13 of 22

 

('a'+'b', 13.1<100, )

 

expressions are evaluated first

('ab',True)

card 14 of 22

 

len(((1,2,3),'b'))

 

in counting items, ignore that an item is a tuple

2

card 15 of 22

 

(1,2)+(1,2)

 

the + operator works somewhat like string concatenation

(1,2,1,2)

card 16 of 22

 

()+(1,2,3,False,4)

 

the empty tuple behaves similar to empty string

(1,2,3,False,4)

card 17 of 22

 

3*(True,False)

 

the * operator is similar to repeated addition

(True,False,True,False,True,False)

card 18 of 22

 

(3,2,1)+(0)

 

look carefully

TypeError: cannot concatenate tuple and integer

card 19 of 22

 

5 in (1,2,3)

 

the "in" operator behavior is similar to string in-test

False

card 20 of 22

 

(1,2) in (1,2,3)

 

"in" operator behavior is not quite the same as string in-test

False

card 21 of 22

 

(1,2) in (0,(1,2),3)

 

"in" operator behavior is not quite the same as string in-test

True

card 22 of 22

 

5 not in (1,2)

 

common sense

True

 

End of Problem Set

(use browser reload to restart this problem set)