Python学习笔记:字符串
startswith 检测开头
示例:

1. a = 'leonis'
if a.startswith('le’):
print ‘le’

endswith 检测结尾
示例:

1. a = ‘leonis'
if a.endswith(‘is’):
print ‘is’

in 检测是否为其中一部分
示例:

1. a = ‘leonis’
if ‘o’ in a:
print ‘a’

find 查询包含
示例:

1. a= ‘leonis’
if a.find(‘on’) != -1:
print(‘on’)

join 连接字符串
示例:

1. a = ' '
mylist = ['Brazil','Russia','India','China']
print a.join(mylist)
2. mylist = ['Brazil','Russia','India','China’]
print ‘_’.join(mylist)

split 拆分字符串

1. b = 'my..name..is..leonis’
print b
print b.split('..’)
2. b = ‘my..name..is..leonis’
print b
print b.split(‘..’,1)