| This article is to share with you the PythonArray andJSArrayRelated content, come together to look at it, hope to learn Python to help you. Createbasically the same Js varperson = [' Xiaohong ', ' Wangwei ', ' Liudehua ']; Python person=[' Xiaohong ', ' Wangwei ', ' Liudehua '] Accessing elementsbasically the same Js Person[0]//xiaohong Python >>> person[0] ' Xiaohong ' slicesThis is not the same,JswithSlicefunction,pythondo not use this same to complete the slice, in addition,JSThe inside is a comma,pythonThe syntax is a colon. One is the parentheses, the other is the brackets. Js Person.slice (0,2)//["Xiaohong", "Wangwei"] Python >>> Person[0:2] [' Xiaohong ', ' Wangwei '] Get element Indexa clearly forIndexOf, a name ofIndex, Dora Js Person. IndexOf (' Xiaohong ')//0 Python >>> person.index (' Xiaohong ') 0 add a new element to the end Jsfrom the namePush,pythonfrom the nameAppend Js Person.push (' Daniu ')//4 person//["Xiaohong", "Wangwei", "Liudehua", "Daniu"] Python >>> person.append (' daniu ') >>> person [' Xiaohong ', ' Wangwei ', ' Liudehua ', ' Daniu '] Delete Element JS PopDelete the last one,ShiftDelete the first one. pythonThe specified index is arbitrarily deleted, and there arePop, withoutShift Js Person.Pop() "Daniu" Person (3) ["Xiaohong", "Wangwei", "Liudehua"] Person.shift () "Xiaohong" Person (2) ["Wangwei", "Liudehua"] Python >>> person.pop () ' Daniu ' >>> person [' Wangwei ', ' Liudehua '] >>> del (person[0]) >>> person [' Wangwei ', ' Liudehua ', ' Daniu '] SortBasically, it's allSortMethod Js Person.Sort() (3) ["Daniu", "Liudehua", "Wangwei"] Python >>> Person.sort () >>> person [' Daniu ', ' Liudehua ', ' Wangwei '] reversalbasically the same Js Person.reverse () (3) ["Wangwei", "Liudehua", "Daniu"] Python >>> person.reverse () >>> person [' Wangwei ', ' Liudehua ', ' Daniu '] Connection Array Js Jswith Contact,pythonwithExtend vararr = [' A ', ' B ', ' C '] var added=arr.concat ([+]) Added//(6) ["A", "B", "C", 1, 2, 3] Python >>> arr = [' A ', ' B ', ' C ']>>> arr.extend ([+)] >>> arr [' A ', ' B ', ' C ', 1, 2, 3] Joinshould sayPythonThis is a little bit of writing Js vararr = [' A ', ' B ', ' C ', 1, 2, 3] Arr.Join('-') "a-b-c-1-2-3" Python >>> arr = [' A ', ' B ', ' C ']>>> '-'. Join (arr) ' A-b-c ' Meta-grouptuples are immutable,Jsno tuples, if necessary, what are some of the alternative methods? JsNo Python >>> (s=) >>> S.Pop() Traceback (most recentPager Last): File "<PYSHELL#46>", line 1, in S.Pop() Attributeerror: ' Tuple ' object hasNoAttribute ' Pop ' Dictionary JsNone but can be implemented with array workarounds Python >>> phonebook = {' Alice ': ' 2341 ', ' Beth ': ' 9102 ', ' ceil ': ' 3258 '}>>> phonebook {' Beth ': ' 9102 ', ' ceil ': ' 3258 ', ' Alice ': ' 2341 '} Summarycan seePythonin order to simplify the writing of a lot of things, such as the same slice,pythonis more thanJSless code, lots of words. Source: Pinterest |