python learning -list

# List of sequential data types.
# Keywords: List
# syntax: [] with data between separated list of data which may be of any type. Values can be repeated.
= A []
B = [ "devil", "jason", "small", True]

CRUD #
# default list data index from 0 read reverse, beginning from -1.
# List Name [Index]
Print (B [. 1])
Print (B [-2])

# Increase data
# from the list of the last additional data list variable name .append (value)
b.append ( "Star")
Print (b)
# insert data inserted in which position, insert Who? A list of variable names .insert (index data)
# flying students inserted in the third. Index: 2 inserted data: flying
b.insert (2, "flying")
Print (B)

# Modify which data corresponding to the index data modification, what the new value?
b [3] = "eight cooked" # corresponding to the position in the list, re-assignment.
print (b)

# Get a list of length len (list of variable names)
Print (len (b))

# Delete elements in the list variable name .remove (value) list, del list variable name [index]
# b.remove ( "eight cooked")
del b [3]
Print (b)


= C [89,12,44,5,863,455]
# sort
# c.sort () # ascending
# print (c)
# c.sort (Reverse = True) in descending order #
# print (c)

# List reversal - reverse
c.reverse ()
Print (c)

= D [True, False]
# A + list merge list List B
Print (C + D)
Print (C)
Print (D)


= f []
# f [3] = "the Hello" # must exist before the assignment.

Guess you like

Origin www.cnblogs.com/qsmyjz/p/11261145.html