In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the Python sequence". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what the Python sequence is.
Sequence sequence
Sequence (sequence) is a set of sequential elements.
(strictly speaking, it's a collection of objects, but since we haven't introduced the concept of "objects" yet, let's talk about elements for the time being.)
A sequence can contain one or more elements, or no elements at all.
The basic data types we mentioned earlier can be used as elements of a sequence. The element can also be another sequence, as well as other objects that we will introduce later.
There are two kinds of sequences: tuple (fixed value table; also translated into tuples) and list (table)
> S1 = (2,1.3, 'love', 5.6,9,12, False) # S1 is a tuple
> S2 = [True, 5, 'smile'] # S2 is a list
> print (s _ 1 ~ ~ type (s _ 1))
> print (s2jintypep (s2))
The main difference between tuple and list is that once established, the elements of tuple can no longer be changed, while the elements of list can be changed.
One sequence as an element of another sequence
> S3 = [1, [3Jing 4jue 5]]
Empty sequence
> S4 = []
Reference to an element
The subscript of the sequence element starts at 0:
> print (S1 [0])
> print (S2 [2])
> print (S3 [1] [2])
Because the element of list is changeable, you can assign a value to an element of list:
> > S2 [1] = 3.0
> print (S2)
If you do this with tuple, you will get an error message.
So, as you can see, the reference to the sequence is implemented by s [], with int as the subscript
Other citation methods
Range reference: basic style [lower limit: upper limit: step size]
> print (S1 [: 5]) # from start to subscript 4 (elements of subscript 5 are not included)
> print (S1 [2:]) # from subscript 2 to last
> print (S1 [0: 5:2]) # from subscript 0 to subscript 4 (excluding subscript 5), take an element every 2 (the element whose subscript is 0mem2re4)
> print (S1 [2: 0 muri 1]) # from subscript 2 to subscript 1
As you can see from above, if the upper limit is specified when the range is referenced, then the upper limit itself is not included.
Tail element reference
> the last element of print (S1 [- 1]) # sequence
>
Similarly, if S1 [0:-1], then the last element will not be referenced (again, excluding the upper bound element itself)
The string is a tuple
A string is a special tuple, so you can perform tuple-related operations.
> str = 'abcdef'
> print (str [2:4])
At this point, I believe you have a deeper understanding of "what the Python sequence is". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.