Python slicing operations

Source: Internet
Author: User

name1 = ' Zcl,pyzyz '
names = [' Zcl ', ' py ', ' zyz ']
#切片的意思就是从list里面或者字符串里面取几个元素
#切片操作对字符串也是完全适用的
# print (Names[0:2])
# #从第几个取到第几个, this is Gu Tou, ignoring the end
# print (Names[:2])
# #如果是从第一个开始取, to the end of a certain subscript, then the front can not be written
# print (names[1:])
# #如果是从前面某个开始取, take it to the end, then you can't write it at the back
# print (names[:]) #如果最前面和最后面都不写的话, take the entire list

#
Nums = List (range (1,11))
# print (Nums[1:10:2])
#如果最后面写上步长的话, is to take it every few
# Nums.reverse ()
Print (Nums)
Print (Nums[::2])
Print (Nums[::-2])
Print (Nums[::-1])
#当切片的步长为负数时, the value is taken from the end, and then taken once every
#如果步长为-1, there's a reversal function.

Python slicing operations

Related Article

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.