python|list-slice

原题:CCC '19 J2 - Time to Decompress

input:    

4
9 +
3 -
12 A
2 X

output:

+++++++++
---
AAAAAAAAAAAA
XX

#answer
L=int(input())

for _ in range(L):
    vals=input().split()
    N=int(vals[0])#why this works?
    ch=vals[1]
    print(ch*N)

question: 我认为【0】对应第一位数,那如果input两位数比如12,不就完蛋了吗?

run result: good

猜想:list slice 和string slice 不同

求证:正确。After split turn input into list, the [0] means the first term in list

Exm: >>>list=[1,2,3,4]

        >>>print(list[0])

        result:  1

supplement:

#list and slice 1:how to replace specific items in the list(space and more numbers are the same
numbers=[1,2,3,4]
numbers[1:3]=[8,9]
print(numbers)#[1,8,9,4]

#list and slice 2:how to replace numbers in items with string
numbers2=[1,2,3,4]
numbers2[1:3]='wat?'
print(numbers2)#[1,'w','a','t','?',4]
#"Introducing python P102

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值