44-公鸡变蛋
原题链接:35067.小派专属2025-01-04 22:42:11
发布于:江苏
list1 = ["c", "o", "c", "k"]
cock = "".join(list1) #join方法,连接拼接. '连接符'.join(列表)
print(cock)
#切片:从列表或者字符串中利用索引切取部分内容 [start:end], 注意取头不取尾
cook = cock[0:2] + "o" + cock[3]
print(cook)
ok = cook[2:] #冒号后省略表示到最后,
print(ok)
coo = cook[:3] #冒号前省略表示从最开始切,
print(coo)
eoo = coo.replace("c", "e") #replace(a, b, cnt), a替换成b, 替换cnt次
egg = eoo.replace("o", "g")
print(egg)
list2 = list(egg) #转换为列表
print(list2)
list2.pop() #默认删除最后, 返回删除的内容
list2.insert(0, "b")
print(list2)
list2[1] = "i"
print(list2) #big
list2[-1] = "n"
print(list2) #bin 箱子
list2 = ["c", "h"] + list2[1:]
print(list2) #chin 下巴
list2.remove("n") #删除指定元素
list2.append("c")
list2.append("k")
print(list2) #chick
list2.append("e")
list2.append("n")
print(list2) #chicken
这里空空如也
有帮助,赞一个