- 按索引取值
- 切片
- 长度len
- 成员用算in\not in
- 移除空白strip
- 切分split
- 循环for
- lstrip\rstrip
- lower upper
- startswith endswith
- rsplit
- join
- replace
- isdigit
msg ='Helle John'
print(f'{msg[6]}')
print(f'{msg[3:7:4]}')
print(len(msg))
print(f"{'john' in msg}")
print(f"{msg.startswith('Helle')}")#endswith 末尾
print(f"{msg.strip('h')}")# 移除两端
msg_list = msg.split('e') #rsplit()右切割
print(f'{msg_list}')
for i in msg:
print(i)
print(f"{msg.lstrip('h')}") #右移rstrip
print(f"{msg.lower()}")
print(f'{msg.upper()}')
jion()
lis = [1,2,'19']
print(f"':'.join(lis): {':'.join(lis)}") # 报错,数字不可和字符串拼接
# str之join()
lis = ['nick', 'male', '19']
print(f"':'.join(lis): {':'.join(lis)}")
':'.join(lis): nick:male:19
replace()
name = 'nick shuai'
print(f"name.replace('shuai','handsome'): {name.replace('shuai','handsome')}")
name.replace('shuai','handsome'): nick handsome
lidigit()
salary = '111'
print(salary.isdigit()) # True
salary = '111.1'
print(salary.isdigit()) # False
True
False
- 其他操作
- find|rfind|index|rindex|count
- center|ljust|rjust|zfill
- expandtabs #默认制表符为8
- captalize|swapcase|title
- is系列