Python:String Functions

From Progzoo
Jump to navigation Jump to search

The methods and properties of the String type include:

s="Andrew was here"
s+" once""Andrew was here once"The strings are concatenated using +
s == "another"FalseTests for equality - use != for not equals
s.find("was")7Returns -1 if the substring is not there.
len(s)15The number of characters
s.split(" ")("Andrew","was","here")Returns an array of String.
s[2:7]"drew"Characters from position 2 to just before 7
s.upper()"ANDREW WAS HERE"Also lower()