Python Beginner-List

Source: Internet
Author: User

List operations: Lists generally need to call the method before printing, can not directly print the method of the call because the list can be modified generally does not return a new list # list # new_names = [' Lzc ', ' lzc2 ', ' lzc3 ']# subscript, index, corner Mark # Computer count is starting from 0   #查询 # new_names = [' Lzc ', ' lzc2 ', ' lzc3 ']# print (new_names[0]) #取值只有这一种方式  # print (New_names.count (' Lzc ')) # Number of occurrences of the query element # print (New_names.index (' lzc3 ')) #查询元素的下标 if there are duplicate elements in the list, only the subscript list of the first element is accessed and the string has the index method but the list does not have a Find method    # Each write code, is in the memory of the application of space, every time the things are stored in memory # when the code is finished running, the code will not consume memory, memory will be released  # add # new_names.append (' Liu ') #从末尾增加元素 # new_names.insert (0, ' Zunchang ') #从指定位置添加 # Print (new_names)  # Change # new_names[0]= ' Liuzunchang ' # print (new_names)  # Delete # del new_names[0] in parentheses is subscript # new_names.pop () #默认删除最后的一个元素 parentheses are subscript # New_names.pop (2) #默认删除最后的一个元素, Specifies the element subscript after the deletion of the specified element # print (new_names) # new_names.remove (' lzc ') #删除 parentheses with the concrete element # Remove Write element pop is the Write Index # names.clear () #清空列表   # invert # print (' Invert before: ', New_names) # # New_names.reverse () # print (' After invert: ', new_names)   #排序 # nums=[ 4,2,5,212,1,55,3,72]# print (' Pre-sorted: ', nums) # Nums.sort () #排序, by default ascending sort can only be sorted for int type, other types will error # Nums.sort (Reverse=true) #排序, write reverse=true) is descending # print (' Sorted by: ', nums)   #扩展列表 # new_names.extend (nums) #把nums元素加到news_name中, Merge two list,.extend itself is not returned, so need to print # print (new_names)  # haha=new_names+nums #拼接两个列表形成新列表 # print (haha)  in# if ' Lzc ' in usernames: #用in来判断一个值在不在一个list里面 # is not judged by a list --------------------------------------------------- --------------------------------------------------Other: # Print (Names.count (' hsdfsdf ')) #查找值在list里面的次数 # Print (names[ -2])) #下标是-2, which represents the last element  # print (' names ', names) # Print (Names.index (' Yinwenqiao ')) #返回查找元素的下标, if there are multiple words to return the first one, If not, it will error # Print (Names.index (' Yinwenqiao ', 3,4)) #后面可以加上查找开始位置和结束位置stus = [' YANGWB ', ' yangwn ', ' Yanghj ']# print (' Add up ', stus+names) #两个列表合并   # nums = [23,34,21,2,456,35,12324324]# print (' Sort descending: ', nums) # print (nums) # Print ( NAMES[-3]) #下标是-1 words, Represents the last element------------------------------------------------------------------------------------------------------------list--number Group # others=[1,2,3,4, ' Liuzun ', ' Zunchang '] #一维数组 # # nums=[1,2,3,4,[' wwe ', 'Lzc ', ' QQQ ']] #二维数组 # print (nums[4][1]) # # num2=[2,3,1,4,[5,3, ' ll ', [22,1,33]] [#三维数组 # Print (num2[4][3][2]) # print (num2[ -1][-1][-1]) #-1 represents the last underlying value in the array # list=nums[4].index (' Lzc ') # print (list)   # list comparison string advantages, easy to fetch data  ---- -------------------------------------------------------------# slice # nums=[1,2,3,4,5,6,7,8,9]# print (Nums[2:7]) # Slice value Gu Tou regardless of tail  # print (Nums[:7]) # # If the top subscript does not write the value to the first place to write # print (nums[2:]) # If the last subscript does not write the value to the last Face # print (nums[:]) #如果最后 is not written before and after, representing all values # print (Nums[2:7:2]) #隔两个取一个值 # print (' Step 1 ', nums[::]) # print (' Step-1: ', nums[::-1]) #如果步长是负数, That's starting at the end of the back. # nums_re=nums.reversed# print (' QQ ', nums_re) here Nums.reserve () print (nums) equivalent to print (Nums[::-1]) # If the step is-1, there is a reversal function # Step-1 is reversed: [9, 8, 7, 6, 5, 4, 3, 2, 1]# print (names[-3]) #下标是-1, which represents the last element  ------------------------ -------------------------------------------------#强制类型转换函数 #int () #float () #str () #list () #tuple ()   ----- ---------------------------------------------------------------#定义一个空列表  # To remove the value labeled 1  #Add members to the list  # the index of the query element   #计算2在列表中出现的次数   #向列表中添加一个列表   #列表值被改变   #获得5在列表中的位置   #从0开始, That is, insert 6 in 3rd member, the other members move back   #删除列表中第3个成员   #删除列表中第最后成员   #删除列表中的5   #清空列表   #颠倒列表的顺序  # Reorder the members in the list   #升序排序  # reverse the list  # modify the third 66  #判断5是否在列表中   #判断666不在列表中中   #找出三维数组中的最后一个元素的值user =[1,2,3,4,54,[111,222,[6666,111]]]  

Python Beginner-list

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.