python canonical data structure type

python common data type contains 6:

1, Number (number)

2, String (String)

3, List (list)

4, Tuple (tuple)

5, Set (collection)

6, Dictionary (dictionary)

 

A, Number (digital)

Including int, float, bool (python3), complex (negative) types

 

Two, List (list)

list is an ordered set of objects, the index value to the starting value 0, -1 from the end of the start position.

The main operating functions are as follows:

)) # 2, for use with ordinary function enumerate Robin. for i in range (len (list1 )):
































print ( "Index:" + str (i), ", the value" + List1 [I])

for index, value in the enumerate (List1):
print ( "Index:" + str (index), ", value:" + value)


# sort
List2 = [9,3,4,2,45]
list2.sort ()
"sorted" Print (, List2)
list3 = [ "S", "D", "F", "R & lt", "L"]
list3.sort ()
( "sorted", list3) Print

# inversion
list2.reverse ()
Print ( "after reverse", List2)
list3.reverse ()
Print ( "after reverse", list3 )

# adding
list + = List2 list3
Print ( "list by adding two list", list)

# clear
list.clear ()
Print ( "clear clears the list", list)

A list can be converted to a string

Small example:

= List1 [ "CHK", "ldlk", "lkvl", "lkdjsflk", "sdfkj"] 
SR = "" .join (List1)
Print (type (SR))

if the transformed list contains numbers being given "error: sequence item 2: expected str instance, int found", list comprising a string of numbers can not be directly converted
solution: print ( "" .join ( ' % s'% id for id in list1))
list1 = ["chk","ldlk",1,2,"sdfkj"]
sr1 = " ".join('%s' %id for id in list1)
print(sr1,type(sr1))


 

Guess you like

Origin www.cnblogs.com/ruguokeyi/p/11837108.html