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. java中xxe漏洞修复方法

    java中禁止外部实体引用的设置方法不止一种,这样就导致有些开发者修复的时候采用的错误的方法 之所以写这篇文章是有原因的!最早是有朋友在群里发了如下一个pdf, 而当时已经是2019年1月末了,应该不 ...

  2. vue页面传参

    1.传的参数是数组 传递参数的页面 let setStr = encodeURIComponent(JSON.stringify(this.tableData)); this.$router.push ...

  3. supervisor配置详解(转)

    有阵子没写博客了,这段时间一直在研究python django框架和前端相关的东西.楼主学通信的,对web这一块啥也不懂,学了一个礼拜django,接着学了2个礼拜前端,感觉还是做不出来一个好看的页面 ...

  4. sitecore8.2 基于站点来查询item

    树形结构: /sitecore /content /foo-site /home /my-account /bar-site /home /my-account /baz-site /home /my ...

  5. mac系统如何处理来自身份不明的开发者

    打开终端(终端在 应用程序 -> 实用工具 内) sudo spctl --master-disable

  6. python -yield理解

    参考:https://foofish.net/iterators-vs-generators.html 从网上看到一个面试题,求最后的输出结果: def add(n, i): return n+ide ...

  7. React 列表页面传递参数

    React 列表进入详情页面 首先安装 react-router-dom (4.0) npm/yarn install react-router-dom 路由跳转配置 列表 父组件 this.prop ...

  8. FairyGUI TextField

    记录一个在使用FairyGUI的TextField时遇到的坑. TextField有一个文本模板功能,可以实现类似占位符的功能,如:{ number = 0 },然后我们可以在脚本中修改number的 ...

  9. bash 基础命令

    bash的基础特性(): () 命令历史 history 环境变量: HISTSIZE:命令历史记录的条数: HISTFILE:~/.bash_history: HISTFILESIZE:命令历史文件 ...

  10. String,StringBuilder,tringBuffer

    这三个类之间的区别主要是在两个方面,即运行速度和线程安全这两方面. 运行速度,或者说是执行速度,在这方面运行速度快慢为:StringBuilder > StringBuffer > Str ...