Flashcards
Slicing, list and dict methods, sorting, unpacking, Counter and defaultdict, sets and hashing, comprehensions and generators, copies and complexity, with verified outputs.
Using this list, what do s[1:4], s[-2:] and s[:3] return?
s[1:4]
s[-2:]
s[:3]
Tap to flip
s[1:4] gives ['b', 'c', 'd'], s[-2:] gives ['e', 'f'], s[:3] gives ['a', 'b', 'c'].
['b', 'c', 'd']
['e', 'f']
['a', 'b', 'c']
The start is included, the stop is excluded, and a slice never raises IndexError for out-of-range bounds.
Tap to see the front