Commit 6e40b1f0 by BellCodeEditor

auto save

parent d84e0f6c
Showing with 15 additions and 8 deletions
# 臂力挑战赛 1.列表的创建 列表名 赋值号 [数据,数据] 例: name = ["jack","mick","milk"]
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中? 2.列表中数字和字符串可以同时出现
name='刘强' 3.列表可以存放多个数据,功能类似于变量,但是比变量存放的数据多
power=66
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
# 自动排序
删除列表中的指定元素可以使用:pop() remove() 3
第一种,利用pop和从左到右正序数索引,索引从0开始
b.pop(3)
第二种,利用remove方法,删除指定元素,第一次出现的
b.remove("关羽")
第三种,利用pop和从右往左倒序数索引,索引从-1开始
print(hero)
\ No newline at end of file 在列表中插入一个数据,可以使用insertappend
insert是在指定位置插入一个数据,我们可以任意挑选位置,位置是列表的索引
append是在列表末尾插入一个数据,仅允许插入1
extend是在列表中插入一个新的列表
在字符串中,单引号和双引号的功能是一样的,都是标识字符串,要成对出现
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment