day_06_Python作业

count的实现,实现统计元素个数

list1 = ['aa', 'bb', 'cc', 'aa', 'cc', 'aa']
count1 = 0
length = len(list1)
for x in range(length):
    if list1[x] == 'aa':
        count1 += 1
print(count1)
image.png

index索引位置的实现,第一个值

list1 = ['aa', 'bb', 'cc', 'aa', 'cc', 'aa', 'dd']
aa = 'dd'
index1 = 0
length = len(list1)
for i in range(length):
    if list1[i] == 'dd':
        index1 = i
        break
print(index1)
image.png

extend实现末尾增加多个值

list1 = ['aa', 'bb', 'cc', 'aa', 'cc', 'aa', 'dd']list4 = 'aasdjhf'
list4 = list(list4)
mudi_list = list1 + list4
print(mudi_list)
image.png

reverse序列逆序的实现

list1 = ['aa', 'bb', 'cc', 'aa', 'cc', 'aa', 'dd']
length = len(list1)
for i in range(length // 2 - 1):
    flag = list1[i]
    list1[i] = list1[length - 1 - i]
    list1[length - i - 1] = flag
print(list1)
image.png

你可能感兴趣的:(day_06_Python作业)