Commit ed2985d1 by BellCodeEditor

auto save

parent 26b3b1d4
Showing with 45 additions and 14 deletions
# 臂力挑战赛
# 快用你机灵的小脑瓜想想,如何将刘强和他的臂力值自动插入到hero列表中?
name=input("叫啥?")
power=int(input("力量值"))
hero=['赵一',30,'丁二',37,'孙五',52,'王猛',89,'周亮',98]
for i in range (len(hero)):
if i%2==1 and hero[i]>=power:
hero.insert(i-1,name)
hero.insert(i,power)
break
print(hero[-6:])
# 和你的小伙伴用列表讲讲桃园结义的故事,并说说这其中运用了哪些列表知识: # 和你的小伙伴讲讲史上有名的三英战吕布的故事。然后完成下面挑战,并说说列表切片是什么,怎么用:
# 来,我给你起个头~
# 从前啊,有三个bro,分别是:刘备、关羽、张飞... # 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
bro1="关羽" a=['吕布']
bro2="刘备" b=['袁术','公孙瓒','关羽','张飞','刘备','曹操']
bro3="张飞"
bros=["刘备","关羽","张飞"] c=b[2:5]
bro1=["关羽",160,8.5] a.extend(c)
bro2=["刘备",161,9.1] print(a)
bro3=["张飞",166,8.3]
bros[0]="关羽"
bros[1]="刘备"
print(bros)
\ No newline at end of file # 增加
a.insert(1,"元素")
a.append("在末尾添加")
a.extend(b) #参数是列表
#删除
a.pop() #删除的索引值,整数是从左到右,负数是从右到左
a.remove()#删除指定元素,是从左到右
#修改
a[0]="张三"
#查询
# 1 通过索引值来查询
a_1=a[4]
#通过切片来查询
b = a[3:6] #取左不取右,不写全都取
b=[:]
\ No newline at end of file
++ "b/d\343\200\202\346\234\213\345\217\213"
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