/    /  Python – Sequences

Python – Sequences:

Sequence in Python can be defined with a generic term as an ordered set which can be classified as two sequence types. They are mutable and immutable.

There are different types of sequences in python. They are Lists, Tuples, Ranges.

Lists: Lists will come under mutable type in which data elements can be changed.

Tuples: Tuples are also like Lists which comes under immutable type which cannot be changed.

Ranges: Ranges is mostly used for looping operations and this will come under immutable type.

The common Sequence Operations are listed below:

x in s : Returns true if an item in s is equal to x

x not in s : Returns false if an item in s is equal to x

s+t  : concatenation

s*n  : adding s to itself n number of times

s[i] :ith item of s, index starts from zero

s[i:j]: slice of s from i to j

len(s) : length of s

max(s) : largest item in s

min(s) :  smallest item of s

s.count(x): total number of occurrences of x in s