python characters taken [-1], [: - 1], [:: - 1], [n :: - 1] and the like explain in detail the method used (recommended retained)

Detailed features characters taken involving python explain:

    = STR '0123456789' 
    Print ( "STR [0: 3]:" + STR [0: 3]) # 0 to 3, the forward taken string (excluding 3) i.e. 012 
    Print ( "STR [:]:" + str [:]) # positive output all strings i.e. 0123456789 
    Print ( "STR [. 6:]:" STR + [. 6:]) # 5 from the forward output string (excluding 5) end i.e. ~ 6789 
    Print ( "str [: - 3]: " + str [: - 3]) # ~ positive output from the start of the countdown of three characters (excluding third) i.e. 0123456 
    Print ( "STR [2]:" + STR [2]) # i.e., output of the third character 2 
    Print ( "STR [: -. 1]:" STR + [: -. 1]) output from the forward start ~ # penultimate first character (which does not contain a ) i.e. 012345678 
    Print ( "STR [-1]:" + STR [-1]) # i.e., output of the last character. 9 
    Print ( "STR [-3: -1]:" STR + [-3: -1]) # reverse order output from the penultimate penultimate 3 to 1 (exclusive) i.e. 78 
    Print ( "STR [-3:]:" STR + [-3:]) # reverse order output from the third to the last countdown i.e. 789 
    Print ( " str [:: - 1]: " + str [:: - 1]) # reverse order output,All i.e. continuous output string 9876543210 All i.e. continuous output string 9876543210 
    Print ( "STR [:: - 2]:" + STR [:: - 2]) # reverse order output from the last start, outputs a string of two every 97,531
    Print ( "STR [::. 1]:" + STR [::. 1]) # n-order output, i.e. continuous output all strings 0123456789
    print ( "str [:: 2] :" + str [:: 2]) # n-order output, starting from the first one, every two outputs a string that is 02468 
    Print ( "STR [: - 2:. 4 ]: "+ str [: - 2: 4]) # n outputted from the first sequence start, a character output every four i.e. 04 
    Print (" STR [. 1: -2:. 4]: "STR + [. 1 : -2: 4]) # n outputted from the second sequence start, a character output every four i.e. 04

Simple law Summary: There are two general forms of string interception
          [:] This form is where to intercept where to find it if it is negative from the back
          [::] The first such form: string representing processing second: intervals taken positive number represents positive output, a negative output representative of reverse

Output is as follows: 
STR [0:. 3]: 012 
STR [:]: 0123456789 
STR [. 6:]: 6789 
STR [: -. 3]: 0123456 
STR [2]: 2 
STR [: -. 1]: 012345678 
STR [- . 1]:. 9 
STR [-3: -1]: 78 
STR [-3:]: 789 
STR [:: -. 1]: 9876543210 
STR [:: - 2]: 97531 
STR [::. 1]: 0123456789 
STR [ 2 ::]: 02468 
STR [: - 2:. 4]: 04 
STR [. 1: -2:. 4]: 15

  

---------------------
reference link: https: //blog.csdn.net/qq_21840201/article/details/85084621

Guess you like

Origin www.cnblogs.com/xiohao/p/11261809.html