in python lists, tuples, dictionaries brief

Briefly explain, I had contact with C ++ language, Java language and then in order to write automated test scripts came in contact with the python language. Although I am not a programmer Daniel (developer). But I contacted several languages, if you want to learn programming, I have not studied before, so I really suggest that you go to learn quite a python. I also understand why there saying "life is short, I use python"

First, that under these definitions:

1, a list (list): a series of specially configured to store information, the list in square brackets [] is defined using data comma separated

Figure:

2, a tuple (Tuple): and a list of similar, except that the elements of the tuple can not be modified, using the definition of the tuple parentheses () defined data using comma separated

Figure:

Lists and tuples are indexed from 0, the data is index position number in the list, the index has been called subscript

Such as: list1 [0] Description: variable name in parentheses next to the number in this example is the subscript meaning the first element of the variable named in list1.

3, the dictionary (dictionary): in addition to the list is the most flexible Python data type, typically used for storing information related to an object described in braces {} dictionary definitions.

Storing dictionary data using key-value pairs with commas between the key-value pairs, separated

Key is an index key, the value of the data value, semicolon between the key and values: the partition, must be a unique key value can be any number of all types, but can only use the key strings, numbers and tuples (where required. note)

Figure:

 

 

Having simple lists, tuples and dictionaries, and today I mainly want to explain the difference at three:

1, lists and tuples are ordered, and disordered dictionary. Briefly the same each time the print dictionary, before and after the order is random key pairs

2, the value of the tuple is not modified, and a list of the dictionary can be modified

3, very special is a tuple, when only one element, you need to add a comma after the element that represents only a tuple

4, the list of built-in method than tuples and dictionaries to the conventional operation containing a list of add, modify, delete, statistics, sorting

  In particular, note that the list is sorted comes, .sort list name () method can sort the list, Sort reverse the default parameter value is False, that is, in ascending order When the reverse to True when , was descending order

Figure:

 

 The output is:

 

 Also note that:

Tuples and lists can be converted to each other:

List function can use a tuple into a list:

  List (tuple)

Tuple list function can be used to convert a tuple:

  tuple (list)

 

Guess you like

Origin www.cnblogs.com/eaglely/p/11571342.html