Operations on Sequences

The following operations apply to all sequences

  • Strings, lists, and tuples.
     s + r              Concatenation
     s * n, n * s       Makes n copies of s where n is an integer
     s % d              String formatting (s is a string)
     s[i]               Indexing
     s[i:j]             Slicing
     x in s             Membership test
     x not in s         Membership test
     len(s)             Length
     min(s)             Minimum item
     max(s)             Maximum item

Examples

     a = [1,2,3]
     b = [5,6]
     c = a + b          # c = [1,2,3,5,6]
     d = a * 2          # d = [1,2,3,1,2,3]
     e = c[2:4]         # e = [3,5]
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 55
July 17, 2000, beazley@cs.uchicago.edu
>>>