string

# !D:\Python
# Filename:str_methods.py

name = 'Swaroop' # this is a string object
if name.startswith('Swa'):
    print 'Yes, the string startwith "Swa"'

if 'a' in name:
    print 'Yes, it contains the string "a"'

if name.find('war') != -1:
    print 'Yes, it contains the string "war"'

delimiter = '_*_'
mylist = ['Brazil', 'Russia', 'India', 'China']
print delimiter.join(mylist)

结果:
Yes, the string startwith "Swa"
Yes, it contains the string "a"
Yes, it contains the string "war"
Brazil_RussiaIndia*_China

====================

你可能感兴趣的:(string)