Python string slices

Source: Internet
Author: User

#-*-coding:utf-8-*-#string Slicesnames="ABCDEFGH"" "Slice Syntax names[start position: End Position: Step] Start Position: That is, the subscript of the string, can be a positive sequence subscript (0,1,2 ...), can also be reverse subscript ( -1,-2,-3 ...) Terminating position: is also the subscript of a string, but unlike the starting position subscript, the element pointed at the terminating position is not included in the inner stride: The default value is 1, when the step >0, which means traversing from left to right, when the step is <0, indicates that the value of the start position or the terminating position is traversed from right to left. Then the direction of the traverse is determined by the positive or negative of the step" "Print(Names[2:5])#Print the value of CDE without names[5]Print(Names[2:6])#Print Cdef#intercept from E to end of stringPrint(names[4:])#Print Efgh#truncate to the second-to-last character starting with EPrint(names[4:-1])#print string at intervalsPrint(Names[::2])#Print Aceg#Reverse Print stringPrint(Names[::-1])

Python string slices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.