码迷,mamicode.com
首页 > 编程语言 > 详细

Python List

时间:2017-01-17 16:55:41      阅读:477      评论:0      收藏:0      [点我收藏+]

标签:item   max   rem   off   removes   tuple   move   value   function   

1. Basic

list1 = [‘math‘, 1, 2.3]

  

2. Accessing

list1 = [‘math‘, 1, 2.3]
list1[0]
list1[1:2]

  

3. delete

list1 = [‘math‘, 1, 2.3]
del list1[0] #‘math‘ will be deleted

  

4. Built-in function

cmp(list1, list2) #Compares elements of both lists.

len(list) #Gives the total length of the list.

max(list) #Returns item from the list with max value.

min(list)

list(seq) #Converts a tuple into list.

list.append(obj) #Appends object obj to list

list.count(obj) #Returns count of how many times obj occurs in list

list.extend(seq) #Appends the contents of seq to list

list.index(obj) #Returns the lowest index in list that obj appears

list.insert(index, obj) #Inserts object obj into list at offset index

list.pop(obj=list[-1]) #Removes and returns last object or obj from list

list.remove(obj) #Removes object obj from list

list.reverse() #Reverses objects of list in place

list.sort([func]) #Sorts objects of list, use compare func if given

  

Python List

标签:item   max   rem   off   removes   tuple   move   value   function   

原文地址:http://www.cnblogs.com/KennyRom/p/6293712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!