1. Sequence. is similar to an array in Java.
Each element in the sequence has a subscript, starting with 0.
Declare a sequence: city=["Beijing", "Shagnhai", "Guangzhou"]
Sequences can contain sequences: city=[["Chaoyangqu", "Haidianqu"],["Xianshi", "Xianyangshi"],["Shenzhengshi"]
ClassStudent(Object):
Def__init__(Self,name,age):
self.name=name
self.age = Age
Xiaoming=student("Xiaoming", one by one)
City=["Beijing",11,xiaoming]
Print str(city)
the elements in a sequence can be of any type.
City=[[],< Span style= "color: #ffffff; Font-weight:bold; " >[ ],[ "Niaochao" print " Span style= "color: #00cccc;" >str ( city[[0][0]
All sequences can perform certain operations. Slice, index, add, multiply, find the largest and smallest elements, and determine whether an element is in the sequence.
The index is accessed by subscript: city[0]
Slice: Selects the element of the specified interval City[1:3], the first index is the number of the first element that needs to be fetched, the last index is the number of the first element remaining after the Shard,
In short, a slice is required to provide two indexes as a boundary, the element of the first index is contained in the content, and the number element of the second index is not included in the content.
The sum of the sequences, and the spelling up.
Multiplication of sequences, and replication several times.
The sequence can be deleted by deleting the element del[i] by subscript.
City=[["Zhongguo"],["Chaoyangqu"],[ "Niaochao" Span style= "color: #ffffff; Font-weight:bold; " >],[ "Shuilifang "],[ "Tushuguan" Del city[0]
print str ( city
List method: lst=[1,2,3],lst2=[9,8]
append (): Appends a new object to the end of the list: Lst.append (4)
COUNT (): Calculates the number of occurrences of an element in the list: Lst.count (1)
Extends () extension of the original list: Lst.extends (LST2), lst=[1,2,3,9,8]
Pop () removes an element that defaults to the end of Lst.pop ()
Sort () sorts the original list. Lst.sort (), returns an ordered list.
So how do you not change the original sequence?
Method One: You can take advantage of the sorted () function. Cases:
Keyword sort: key
Length (len) Sort:
Sort by keyword: reverse ()
Note: reverse = True Descending
Reverse = False Ascending
Set function
Features: Lists the non-repeating elements (deduplication) collection in the list. Example:
Note: Using the Set () function becomes a set, the set of example elements unordered, and then using list2[2] error.
Main function: Len (seq) returns the sequence length
List (seq) to convert a sequence to a table
Tuple (SEQ) to convert a sequence to a tuple
Sorted (SEQ) sorts the sequence to return a new sequence.
Python data structure