2. 使用python把列表["王五","张三","李四","王麻子","张无忌","张三丰","李云龙"]中姓张的名字删除。
时间: 2024-04-23 12:20:27 浏览: 200
python实现删除列表中某个元素的3种方法
要删除列表中姓张的名字,可以使用Python的列表推导式和字符串的startswith()方法来实现。以下是代码示例:
```python
names = ["王五","张三","李四","王麻子","张无忌","张三丰","李云龙"]
names = [name for name in names if not name.startswith("张")]
print(names)
```
输出结果为:["王五", "李四", "王麻子", "李云龙"]
阅读全文