name='muziyi'
print(name.capitalize())
print(name.count('i'))
print(name.center(50,'-'))
print(name.endswith('yi'))
>>>
Muziyi
2
----------------------muziyi----------------------
True
name='my name is {name} and I am {age}'
print(name.format(name='muziyi',age=26))
print(name.format_map({'name':'muziyi','age':26}))
>>>
my name is muziyi and I am 26
my name is muziyi and I am 26
name='my name is {name} and I am {year}'
print(name.find('name')) #返回字母的索引
print(name[name.find('name'):]) #字符串可以通过find语句切片
>>>
3
name is {name} and I am {year}
print('swan777'.isalnum()) #字符串只包含字母和数字为true,否则为false
print('swan777、、'.isalnum())
print('abA'.isalpha()) #字符串只包含字母为true,否则为false
print('abA456'.isalpha())
print('456'.isdigit()) #字符串为整数为true,否则为false
print('dd456'.isdigit())
print('45.6'.isdigit())
>>>
True
False
True
False
True
False
False
True
print(','.join(['1','2','3']))
print('+'.join(['1','2','3']))
>>>
1,2,3
1+2+3
name="muziyi"
print(name.ljust(20,'*'))
print(name.rjust(20,'*'))
>>>
muziyi**************
**************muziyi
print('MUziyi'.lower()) #字符串中大写变小写
print('muziyi'.upper()) #字符串中小写变大写
>>>
muziyi
MUZIYI
print('第一种')
print('muziyi
')
print('****')
print('--------------')
print('muziyi
'.rstrip())#去掉右面的换行符或空格
print('***')
print('第二种')
print(' muziyi')
print('****')
print('--------------')
print(' muziyi'.lstrip())#去掉左面的换行符或空格
print('****')
print('--------------')
print('第三种')
print(' muziyi
')
print('****')
print('--------------')
print(' muziyi
'.strip())#去掉两面的换行符或空格
print('****')
>>>
第一种
muziyi
****
--------------
muziyi
***
第二种
muziyi
****
--------------
muziyi
****
--------------
第三种
muziyi
****
--------------
muziyi
****
print('muziyi'.replace('i','l',1)) #替换
print('muziyi'.replace('i','l',2))
print('muziyi'.rfind('i')) #最右面’i'的下标
print('muziyi'.find('i'))
>>>
muzlyi
muzlyl
5
3