(1)字符串的搜索
定义字符串s = 'hello world hello'
find找到子串,并返回最小的索引
print(s.find(‘hello’))
print(s.find(‘world’))
rfind找到子串,并返回最大的索引
print(s.rfind(‘hello’))
(2)字符串的替换
print(s.replace(‘hello’,‘westos’))
(3)字符串的对齐
print('学生管理系统'.center(30))左右两边各15个空格
print('学生管理系统'.center(30,'*'))左右两边均15个*
print('学生管理系统'.ljust(30,'*'))左对齐,右边用*补齐
print('学生管理系统'.rjust(30,'*'))右对齐,左边用*补齐
(4)字符串的统计
print('hello'.count('l'))统计字符串中l的个数
print('hello'.count('ll'))统计字符串中ll的个数
print(len('hello'))统计字符串的长度
(5)字符串的分离
定义字符串s = '172.25.254.250'
s1 = s.split(’.’)
print(s1)
(6)字符串的连接
print(’.’.join(s2))
(7)字符串的反转
hello westos python
python westos hello
print(' '.join(input().split()[::-1]))先分离,再逆向,再连接
(8)去掉字符串中的元音字母
They are students输入1
aeiou输入2
Thy r stdnts输出结果