如何删除没有列出索引的数组的特定元素

zujrkrfu  于 2022-10-22  发布在  Python
关注(0)|答案(1)|浏览(126)
Attendance = ['Holly','James','Barry','John','Lewy']

Present = input("Is number Holly present?")

if Present == "N":
    Attendance.pop("Holly")

print(Attendance[0])

是否仍要按名称从数组中删除特定术语?这似乎不管用?或者我只能通过列出数组的索引来删除数组的特定元素吗?

myss37ts

myss37ts1#

是的,可以使用LIST_VARIABLE.remove('ELEMENT_TO_BE_REMOVED')

Attendance = ['Holly','James','Barry','John','Lewy']
print(Attendance)
Attendance.remove('Holly')
print(Attendance)

输出将是:

['Holly', 'James', 'Barry', 'John', 'Lewy']
['James', 'Barry', 'John', 'Lewy']

相关问题