Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use [:-1] and [::-1] in python

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces "how to use python [:-1] and [::-1]" related knowledge, in the actual case operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!

1. Case interpretation

A='python'b=a [::-1] print (b) # nohtypc=a [::-2] print (c) # nhy#, the last position is-1d=a [:-1] # the number before position 0 to position-1 print (d) # pythoe=a [:-2] # from position 0 to position-2 print (e) # pyth

2. Usage instructions

B = a [i j] means to copy a [I] to a [j-1] to generate a new list object

B = a [1:3] # [1] when I defaults, it defaults to 0, that is, a [: 3] equals to a [0:3]. When j defaults, it defaults to len (alist), that is, a [1:] equals to a [1:10]. When ijis all default, a [:] is equivalent to a complete copy of a.

B = a [i:j:s]: iMagol j is the same as above, but s means step by step, the default is 1. So a [i:j:1] is equivalent to a [I: J] when s

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report