motorcycles = ["honda", "yamaha", "suzuki", "ducati"]
print(motorcycles) motorcycles.remove("ducati")
print(motorcycles)

输出为:

['honda', 'yamaha', 'suzuki', 'ducati']
['honda', 'yamaha', 'suzuki']

2、

motorcycles = ["honda", "yamaha", "suzuki", "ducati"]
print(motorcycles) too_expensive = "ducati"
motorcycles.remove(too_expensive)
print(motorcycles)
print("\nA " + too_expensive.title() + " is too expenfive for me.")

输出为:

['honda', 'yamaha', 'suzuki', 'ducati']
['honda', 'yamaha', 'suzuki'] A Ducati is too expenfive for me.

Python自学:第三章 根据值删除元素的更多相关文章

  1. Python自学:第三章 使用方法pop()删除元素

    motorcycle = ["honda", "yamaha", "suzuki"] last_owned = motorcycle.pop ...

  2. Python自学:第三章 使用del语句删除元素

    motorcycles = ["honda", "yamaha", "suzuki"] print(motorcycles) del mot ...

  3. Python自学:第三章 使用列表中的各个值

    bicycles = ['trek','cannondale','redline','specialized'] message = "My first bicycle was a &quo ...

  4. Python自学:第三章 确定列表长度

    >>> cars = ["bmw", "audi", "toyota", "subaru"] > ...

  5. Python自学:第三章 倒着打印列表

    # -*- coding: GBK -*- #reverse: 相反的 cars = ["bmw", "audi", "toyota", & ...

  6. Python自学:第三章 使用函数sort( )对列表进行临时排序

    # -*- coding: GBK -*- cars = ["bmw", "audi", "toyota", "subaru&qu ...

  7. Python自学:第三章 使用方法sort( )对列表进行永久性排序

    cars = ["bmw", "audi", "toyota", "subaru"] cars.sort() print ...

  8. Python自学:第三章 动手试一试 3-4、3-5

    # -*- coding: GBK -*- liebiao = ["zhang", "li", "wang", "zhou&quo ...

  9. Python自学:第三章 弹出列表中任何位置处的元素

    motorcycles = ["honda", "yamaha", "suzuki"] first_owned = motorcycles. ...

随机推荐

  1. laravel----------Client error: `POST http://47.98.116.219/oauth/token` resulted in a `401 Unauthorized` response: {"error":"invalid_client","message":"Client authentication failed"}

    1.设备没有授权,原因是 这个client_id的值就是数据库wk_oauth_clients 的主键ID,查看下表是否有这条数据

  2. JavaScript 对象部署 Iterator 接口

    const name = { first:"hello", last:"world", fullname: "hello world" } ...

  3. 灵雀云获邀加入CDF(持续交付基金会),成为中国区三大创始成员之一

    3月12日,在加州Half Moon Bay举行的开源领导者峰会(Open Leadership Summit 2019 )上,CDF(Continuous Delivery Foundation ) ...

  4. css基础重点内容总结

    一.目录引入 ./同级(当前) ../上级目录  ../../上上级目录 二.标签种类: 1.块级标签(block):独占一行,宽高可设: 2.行内块标签(inline-block):不独占一行,宽高 ...

  5. tcp ip 协议安全

    ARP(地址解析协议) 地址解析协议,即ARP(Address Resolution Protocol),是根据IP地址获取物理地址的一个TCP/IP协议.主机发送信息时将包含目标IP地址的ARP请求 ...

  6. Linq组合查询与分页组合查询结合

    1.组合查询 <div>姓名:<asp:TextBox ID="T1" runat="server"></asp:TextBox& ...

  7. python 文件重命名

    将文件夹中的.jsp重命名为.html import os def rename(path): files = os.listdir(path) for file in files: dir = os ...

  8. Python 递归计算分数数列

    C语言的课后习题 求数列:2/1,3/2,5/3,8/5,13/8,21/13,...前50项的和 数列规律: 第二项的分母是[前一项分子] 第二项的分子是[前一项分子与分母的和] from frac ...

  9. Oarcle 之连接查询

            连接查询:连接查询是关系数据库中最主要的查询,主要包括内连接.外连接和交叉连接等.通过连接运算符可以实现多个表查询.连接是关系数据库模型的主要特点,也是它区别于其它类型数据库管理系统的 ...

  10. ASP.NET 教程汇总

    channel9 https://channel9.msdn.com/ .net core项目实战 https://study.163.com/course/introduction.htm?cour ...