Python list usage, python list
#! Usr/bin/env python
#-*-Coding: UTF-8 -*-
# The following methods are all run in python2.7.x. Please execute them in the print (put in parentheses) by those above 3. x)
# List methods:
Li = [] # define an empty list;
Li. append (1) # Add a constraint to the end of the list;
Print li
Li2 = [2, 3, 3, 4, 5, 6]
Li. extend (li2) # merge the specified li2 list to the end of the li list;
Print li
Li. insert (6, 0) # insert element 0 at 6th locations in the subscript [also called Index] of li (corresponding to the elements in the list one by one, accumulating from 0 by default)
Print li
Li. remove (4) # Delete element 4 from the list
Print li
S = li. pop () # Delete the last element and return its value
Print li
Print "Return Value pop =", s
A = li. index (1) # locate the position/subscript/index of 1 in the list Li and return its value
Print "1 in the list:",
C = li. count (3) # count the number of times that li appears in the list and return its value
Print "3 times in the list:", c
Li. sort () # elements in the sorting list
Print li
Li. reverse () # reverse the element in the list
Print li
# Print the following output: