This post is a continuation of Python Sequences.
Concatenating Sequences
You can concatenate sequences using the plus (+) operator:
1
2
| >>> [1, 2] + [3, 4]
[1, 2, 3, 4]
|
Multiplying Sequences
You can multiply a sequence by an integer number to repeat it the specified number of times:
1
2
| >>> [1, 2] * 3
[1, 2, 1, 2, 1, 2]
|
Membership
You can verify if a value is inside a sequence by using the in operator. This operator returns a Boolean specifying if the value was or not found:
1
2
3
4
| >>> 4 in [1, 3, 5, 7]
False
>>> 3 in [1, 3, 5, 7]
True
|
Getting the length of a Sequence
1
2
| >>> len([1, 3, 5, 7])
4
|
Getting lowest member of a Sequence
1
2
| >>> min([1, 3, 5, 7])
1
|
Getting highest member of a Sequence
1
2
| >>> max([1, 3, 5, 7])
7
|