CHAPTER 2 ■ NATIVE DATA TYPES
28
no, it's false
>>> is_it_true(['a']) (2)
yes, it's true
>>> is_it_true([False]) (3)
yes, it's true
1. In a boolean context, an empty list is false.
2. Any list with at least one item is true.
3. Any list with at least one item is true. The value of the items is irrelevant.
Tuples
A tuple is an immutable list. As long as you don’t try to change it, a tuple acts just like a list (see
Listing 2-19).
Listing 2-19. Tuples Behave a Lot Like Lists
>>> a_tuple = ("a", "b", "mpilgrim", "z", "example") (1)
>>> a_tuple
('a', 'b', 'mpilgrim', 'z', 'example')
>>> a_tuple[0] (2)
'a'
>>> a_tuple[-1] (3)
'example'
>>> a_tuple[1:3] (4)
('b', 'mpilgrim')
1. A tuple is defined in the same way as a list, except that the ...