the element at the specified position index, default to the last position, if index exceeds range or list is empty, throws an error >>> A ['a' 'b'sddsds'd' , 6, 6, 5, 4, 2, 4] >>> b = a.pop () >>> b9.list.removeList.remove#removes the specified value from the list for the first time, if the specified value does not exist, throws an exception>>>A ['a','b','Sddsds', 1, 3, 4,'D', 6, 6, 5, 4, 2]>>> A.remove ('a')>>>A ['b','Sddsds', 1, 3, 4,'D', 6, 6, 5, 4, 2]10.list.reverseList.reverse#invert an e
Learn Python tuple every dayLearn Python tuple every day
Tuples are a list with restrictions added. The main difference is that once the tuples are determined, they cannot be modified. They can be converted to each other through their constructors.Advantages
Tuples are very similar to lists, but they have their own advantages:Tuples are faster than lists, and a string of values are also traversed. tuples a
into the list
The List.isinstance () function can be used to determine whether a particular identifier contains a particular type of data
Third, Ganso (tuple, ordered, non-modifiable) need to add common operationsHow to create
tuple1 =()
tuple1 = tuple({1,2,3,4,5,‘6‘})
tuple1 = (1, 2, ‘3‘, 4, ‘5‘)
Note: You cannot add or modify elements in a tuple
1Tuple definitions:
Description: Tuples can not be modified, usually enclosed in parentheses.
Example:
#一般元组>>> 1 (2, 3) >>> (1, 2, 3)#一个元素的元组>>> (1,) (1,) >> > 2, (2,)#空元组 #元组的乘法2Tuple function
Description: Converts a sequence to a tuple, using a series parameter;
Example:
>>>tuple("CONSTANT")(' C ',' O ',' N ',' S ',' T ',' A ',' N ',' T ') >>>
Tuple, the first level element cannot be modified, cannot be added or deletedTu = (111, ' Alex ', (11,22), [(33,44)],ture,33,33,)It is recommended to add a comma at the end to distinguish whether the tuple is not an errorcan be called outTu = (111,'Alex', (11,22), [(33,44)],true,33,33= tu[1]print(v )or sliceTu = (111,'Alex', (11,22), [(33,44)],true,33,33= tu[1:3]print (v)Tuples after a
to implement a tuple that includes only one value, you must also add a comma, such as (23,)Tuple function: Takes a sequence as a parameter and converts it to a tuple.Whether a tuple is fragmented or a tuple. Just like a list fragment or a list.
Cases
List
code is as follows
copy code
Six ']Tuple, tuple is a non-modifiable "list", looks and lists are no different
Creating elements
>>> tuple1 = (' small two ', ' Can ', ' come a cup ', ' wine ') >>> tuple1 (' small two ', ' Can ', ' come a cup ', ' wine ')2. Add an element to a tuple (is the tuple not modifiable?) How to add?) It's not
Data type number引号: 123 数值 ‘123‘ 字符串 整数:ini long 范围:(-2**31 - 2**31) num = 123 长整型 long (L) num = 123L浮点型:float复数型:SequenceString, list, tuple all belong to sequenceThe two main features of a sequence are index operations and slicing operations
Index operations can fetch a specific item from the sequence
Slice operations can get a slice from the sequence, which is part of the sequence
Basic operation of
1 #-*-coding:utf-8-*-2 3 #1. Dictionaries4Dict = {'name':'Zara',' Age': 7,'class':' First'}5 6 #dictionary converted to string, return: : ' First '}7 Printtype (str (dict)), str (dict)8 9 #dictionaries can be converted to tuples, returning: (' age ', ' name ', ' class ')Ten Printtuple (dict) One #dictionaries can be converted to tuples, returning: (7, ' Zara ', ' first ') A Printtuple (Dict.values ()) - - #dictionary to list, return: [' age ', ' name ', ' class '] the Printlist (dict) - #Dicti
The characteristic of a tuple is that its elements are immutable (immutable), and once set, it cannot be modified using an index.>>> t1=1,2,3,4,5 #给Tuple赋值 >>> t1[0] #按照索引读取Tuple元素1 > >> u1=t1, (2,3,4,5,6) #tuple可以嵌套 >>> U1 ((1, 2, 3, 4, 5), (2, 3, 4, 5, 6)) >>> U1[1] (2, 3, 4, 5, 6) > >> U1[-1] (2, 3, 4, 5, 6) >>> u1=
))Li.insert (2, ' t ')Print (LI) results: [2, 3, ' t ', 4, 6, 9, 7, 2]8,def pop (self, index=none): Removes the element from the list, you can specify the subscript, by default remove the last Li = List ((2,3,4,6,9,7,2)) ret = Li.pop () print (LI) Result: [ 2, 3, 4, 6, 9, 7] Print (ret) results: 2 9,def Remove (self, value): Removes the specified element li = List ((2,3,4,6,9,7,2)) Li.remove (2) Print (LI) Results: [3, 4, 6, 9, 7, 2]10,def reverse (self): reverses a sequence li = List ((2,3,4,6
Which method does MVC use to pass the Model? Choose between ViewData, ViewBag, PartialView, TempData, ViewModel, and Tuple. mvcpartialview
In "passing multiple models to a view using the MVC controller, using ViewData, ViewBag, partial views, TempData, ViewModel, and Tuple", you can use different methods to pass multiple models, viewData, ViewBag, PartialView, TempData, ViewModel, and
There is an assignment mechanism in Python that assigns values in this way, and the objects on both sides of the equal sign are tuples and the parentheses of the tuples are optional. The usual form is' A String 'Equal to (x, y, Z) = (1, 2, 'a string')The most frequently used environment for this type of assignment is variable exchange, which is shaped likeX, y = y, XThis exchange method does not require an intermediate variable to exchange the values of two variables. So what is the concrete imp
Ticktuple can meet every time a tuple is sent, "__system" component periodically sends a tuple of "__tick" stream to the task,The sending frequency is configured by Topology_tick_tuple_freq_secs and can be configured in the Default.ymal,It can also be configured in the code via Getcomponentconfiguration ().The code is configured as followsPublic mapmapConf.put (Config.topology_tick_tuple_freq_secs, 1); Inte
#-*-coding:utf-8-*-Http://www.cnblogs.com/linjiqin/p/3674356.html#1, DictionariesDict = {' name ': ' Zara ', ' age ': 7, ' class ': ' First '}#字典转为字符串, return: Print type (str (dict)), str (DICT)#字典可以转为元组, return: (' age ', ' name ', ' class ')Print tuple (dict)#字典可以转为元组, return: (7, ' Zara ', ' first ')Print tuple (dict.values ())#字典转为列表, return: [' age ', ' name ', ' class ']Print List (dict)#字典转为列表Print
Li Hongqiang iOS Development Swift article -05_ tuple typeI. Introduction to the type of meta-group1. What is a tuple typeA tuple type consists of n arbitrary types of data (n >= 0), and the data that makes up the tuple type can be called an "element"Example:Let position = (x:10.5, y:20)//position has 2 elements, X, Y
One, the value of the tuple cannot be modified#!/usr/bin/pythontup = ("A", "B", "C"); tup[1]=7The following error occurred after execution:Traceback (most recent):File "C:\Program files\sublime Text 3\time.py", line 4, Tup[1]=7TypeError: ' Tuple ' object does not support item assignmentThe elements of a tuple cannot be deleted individually, only all can be delete
meta-group Tuple tuples , as an upgraded version of the list, is a very secure data structure. The first level of its elements can only be found, can not be increased, deleted, changed.In addition to this, the list supports operations that tuples can support. Tuples can also implement encapsulation and unpacking. When the data we want to create doesn't want to be repairedWhen you change it, be sure to use tuples with confidence. If we really need to
;> len (list)
1
>>> len (list2)
2
>>>
tuple
Tuple: Tuple, also a sequence table. Tuple can not be modified once initialized. If an element in tuple is a list, the list can be changed.1. Define
Define an empty tuple
>>> t= ()
>>>
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.