Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of order and reverse order in python Index

Shulou Source: shulou.com Published: 2022-06-03 17:08:51 10月04日 Update

This article mainly introduces the python index in the order and reverse order of the example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.

Description

1. Python supports not only sequential indexing, but also reverse indexing.

2. The reverse index refers to the index calculated from right to left, and the rightmost index value is-1, which decreases in turn.

3. Note that the reverse order is the same as the order subscript, and both are unsubscribed subscript elements.

Example

Num_str = "0123456789" # 1. Intercept the string print (num_str [2:6]) # 2 from positions 2-5. Intercept the string print (num_ str2:]) # 3 from the end of 2 ~ ``. Intercept the string print (num_str [: 6]) # 4 starting from `~ 5. Intercept the complete string print (num_str [:]) # 5. Intercept the string print (num_str [:: 2]) # 6 every other character from the start position. Starting with index 1, take every other print (num_ str1:: 2) # 7, and reverse slice #-1 represents the penultimate character # all character sequences print (num_ str1:-1]) # 8 with index 1 to the penultimate string. Intercept the string print (num_ stre [2:-1]) # 9 from 2 ~ `\ end-1`. Intercept the last two characters of the string print (num_str [- 2:]) # 10. String reverse (interview questions) print (num_str [::-1]) Thank you for reading this article carefully. I hope the article "sample Analysis of order and reverse order in python Index" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Character index string reverse order article position end support example analysis subscript same two value element interest right at the same time instance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn MariaDB Shulou Tech Info Docker