ListA.append(5)
ListA.remove(1)
ListA.extend([6,7,1])
ListA.insert(0,1)
del ListA[0]
print(ListA)
print(ListA.count(1))
print(ListA.index(1))
print(ListA.index(1,1,len(ListA)))
ListA.pop()
ListA.pop(2)
ListA.reverse()
print(ListA)
ListA.sort(reverse=True)
列表索引
1
2
3
4
5
6
7
ls1 = [‘James’,‘Andy’,1,2,3]
print(ls1[0])
print(ls1[1:])
print(ls1[:3])
ls2 = [‘Nike’,‘Biber’]
ls = ls1 + ls2
print(ls)
字符串操作
字符串的连接
1
2
3
4
str1 = ‘lk’
str2 = ‘psr’
str3 = str1 + str2
print(‘Well Water’+‘River’)
字符串的复制
1
2
3
str1 = ‘I love math’
str2 = str1*3
print(‘I Love U\n’*3)
字符串的转义
1
2
a = ‘Let’s go’
b = r’C:\lk’
多行字符串
1
2
3
4
5
str =
‘’’ lk
lk
lk
‘’’