Lesson 6
Dealing with Sequences of Objects
Chapter 3: More on lists
List operators
Like strings, the operators +
and *
have been overloaded for lists.
So, you can concatenate two lists by ‘adding’ the list together, and replicate elements in a list by ‘multiplying’ it with a scalar.
>>> print([1, 2] + [3, 4, 5])
[1, 2, 3, 4, 5]
>>> print([1, 2] * 3)
[1, 2, 1, 2, 1, 2]
Looking forward to yet another quiz? 😊
❮
❯