Python learns the concept of 5--sequences

Source: Internet
Author: User

1. List, meta-ancestor, string conversion

List (x): X can be a list or a tuple, with the result of converting X to a list, each character of x within an element in the list.
Example: x= ' zj h '; x=list (x), then x=[' Z ', ' j ', ', ' H '];
Tuple (x), convert x to Ganso, str (x), convert x to String, use ibid.

2. Some methods.
Len (x), which returns the length of x;
Max (x), which returns the maximum value in the parameter x (the numeric value, which supports negative numbers).
Min (x), which returns the minimum value in X.
Note: If x is a list, which includes numbers and letters, it will be an error. Because at the time of comparison, the data types should be the same on both sides of the comparison operator.
SUM (X[,y]), which returns the sum of all the elements in the sequence x plus y, where the y parameter is optional and x is not a string.
Sorted (x), the x is sorted;
Reversed (x), returns a reversal that is not X, and the list (reversed (x)) returns the flip of X.
List (enumerate (x)), Example: x= (A/N), the return value after use is [(0,1), (up to), (2,3)];
List (Zip (x, y)), Example: x= (1,2,3,4,4), y= (4,5,6), after use results for [(1,4), (2,5), (3,6)];
Note: All of the above methods are based on the sequence and are manipulated using iterations.
That is, regardless of whether the object is a list, a meta-ancestor, or a string, using the above method to operate the room, they are split into a single element, the results are in the form of a list.
In particular, the string does not support the sum method.
Str= ' ZJHXXR '
>>> Str
' ZJHXXR '
>>> list (reversed (str))
[' R ', ' X ', ' x ', ' H ', ' J ', ' Z ']
>>> Sorted (str)
[' H ', ' J ', ' R ', ' X ', ' x ', ' Z ']
>>> sum (x), error.

Python learns the concept of 5--sequences

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.