DEV Community

Yesra Sajid
Yesra Sajid

Posted on

string:

Strings, lists and tuples are sequences. They can be indexed and sliced in the same way.
Tuples and strings are “immutable” (which basically means we can’t change individual elements within the tuple, and we
cannot change individual characters within a string) whereas lists are “mutable” (.i.e we can change elements in a list.)
Sequences share the following operations
• a[i] returns i-th element of a
• a[i:j] returns elements i up to j-1
• len(a) returns number of elements in sequence
• min(a) returns smallest value in sequence
• max(a) returns largest value in sequence
• x in a returns True if x is element in a
• a + b concatenates a and b
• n * a creates n copies of sequence a

Top comments (0)