String Methods

Strings now have methods

  • Replaces functionality in the string module
     s.capitalize()
     s.center(width)
     s.count(sub [,start [,end]])
     s.find(sub [,start [,end]])
     s.isalnum()
     s.join(t)
     s.lower()
     s.replace(old,new [,maxreplace])
     ...
     

Example

 s = "Hello World"
 t = s.upper()       # t = "HELLO WORLD"
 a = s.split()       # a = ['Hello', 'World']
 
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 27
July 26, 2001, beazley@cs.uchicago.edu
>>>