Attendance = ['Holly','James','Barry','John','Lewy'] Present = input("Is number Holly present?") if Present == "N": Attendance.pop("Holly") print(Attendance[0])
是否仍要按名称从数组中删除特定术语?这似乎不管用?或者我只能通过列出数组的索引来删除数组的特定元素吗?
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']
1条答案
按热度按时间myss37ts1#
是的,可以使用LIST_VARIABLE.remove('ELEMENT_TO_BE_REMOVED')
输出将是: