Strings

Representation

  • Strings are sequences of characters
  • May contain embedded nulls and binary data.
  • Strings are immutable

Common Operations

     s[i]              # Return the ith character
     s[i:j]            # Extract a substring
     len(s)            # String length 

Examples

     s = "Hello World"
     x = s[4]          # x = 'o'
     y = s[0:5]        # y = 'Hello'
     print len(s) 
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 38
July 17, 2000, beazley@cs.uchicago.edu
>>>