Python Learning's general sequence type data detailed

Source: Internet
Author: User

This article shares with you the main isPythonof the generic sequence type data.relatedOperation, let's take a look at it and hope for everyoneLearningpythonhelpful. Pythonthe sequence, Pythonhave a6types of built-in sequences, including: Lists, tuples, strings,UnicodeString,Bufferobjects, andxrangeobject. One of the most commonly used isPythonlists and tuples. Pythonthe sequence Pythonhave a6types of built-in sequences, including: Lists, tuples, strings,UnicodeString,Bufferobjects, andxrangeobject. One of the most commonly used isPythonlists and tuples. PythonApplication of Sequences Pythonwhen you manipulate a set of data, you typically use a sequence to represent this set of information. (sequences can also contain other sequences) PythonThere is also a data structure called a container. A container is any object that contains other objects. sequences (such as tuples and lists) and mappings (such as dictionaries) are two main types of containers. each element of the sequence has its own number (the tuple can be the key name for the dictionary), and each element of the map has its own name (key). There is also a container type that is neither a sequence nor a map, called a collection. General-Purpose sequence operationsdata structures of all sequence types can perform certain operations, such as; index, Shard, plus, Multiply and checks whether each element belongs to a member of a sequence (membership). Indexall elements of a sequence have their own numbering, from0first, access by number is indexed. 1. >>>indexing = ' python ' 2. >>>indexing[1] 3. ' Y ' 4. >>>indexing[-1] 5. ' N 'or string Direct index 1. >>> ' Python ' [0] 2. ' P ' Shardsan index is used to access a single element, while a shard operation is used to access an element within a range. Shards are implemented by two indexes separated by a colon. 1. >>>string = ' Zhizuzhefu ' 2. >>>string[9:30] 3. '/' 4. >>>num= [1,2,3,4,5,6] 5. >>>num[3:6] 6. [4, 5, 6] 7. >>>num[-3:-1] 8. [4, 5] 9. >>>num[-3:] 10. [4, 5, 6] >>>num[:] 12. [1,2,3,4,5,6]The Shard has an implicit setting: step. The steps above are1. For example: 1. >>>num= [1,2,3,4,5,6] 2. >>>num[3:6:1] #This is a hidden step.1 3. [4, 5, 6] 4. >>>num[3:6:2] #Step Change to2 5. [4, 6] sequence Additionuse the plus sign to sequence the connection operation. 1. >>>[1,2]+[3,4] 2. [1,2,3,4] 3. >>>[1,2]+ ' python ' 4. Typeerror:can only concatenate list (not "str") to List 5. #error, the same type of sequence can be connected operation. multiplicationwith a digitalXmultiplied by a sequence to get a new sequence, the new sequence repeats for the original sequencextimes. 1. >>>[1] * 3 2. [1, 1, 1]member Qualifications(detects whether an element belongs to a member of a sequence)to check whether a value is in a sequence, you can use theInchoperator. Returns a Boolean value. 1. >>>per = ' python ' 2. >>> ' py ' in per 3. TrueNote:Inchis case-sensitive.

Python Learning's general sequence type data detailed

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.