Python reverse-stride slicing

前端 未结 8 632
后悔当初
后悔当初 2020-12-02 20:22

A specific example of my question is, \"How can I get \'3210\' in this example?\"


>>> foo = \'0123456\'
>>> foo[0:4]
\'0123\'
>>> foo[::-1]
\'6543210\'
>>>          


        
8条回答
  •  醉酒成梦
    2020-12-02 21:07

    Simply exclude the end range index...

    >>> foo[3::-1]
    '3210'
    

    Ironically, about the only option I think you didn't try.

提交回复
热议问题