startwithmethod is used to test whether a string starts with the given string.
inoperator is used to verify whether a given string is part of another string.
findmethod is used to find the position of the given string in another string, or 1 to indicate that the substring cannot be found.
strThe class also has a neat method for the item with a sequence of strings as a delimiter join , which returns a generated large string.
#!/usr/bin/python# Filename:str_methods.pyname = ' Swaroop ' # This is a string object if Name.startswith (' Swa '): print ' Yes, the string starts with ' Swa ' if ' a ' in Name: print ' Yes, it contains the string ' A ' if Name.find (' War ')! = -1:< C7/>print ' Yes, it contains the string "war" ' delimiter = ' _*_ ' mylist = [' Brazil ', ' Russia ', ' India ', ' China ']print delimit Er.join (MyList)
$ python str_methods.pyyes, the string starts with "Swa" Yes, it contains the string "A" Yes, it contains the string "War" Br Azil_*_russia_*_india_*_china
Python Str method