This article mainly introduces the list of Python data structures, the tuples array, the dictionary dict, the list, and the detailed introduction of the tuples and strings as sequences. The following describes the specific content of the Python data structure, I hope you will gain some benefits,
Python Data Structure
1. list: Variable Assignment Method:
- shoplist = ['apple', 'mango', 'carrot', 'banana']
2. tuples array: Variable Assignment Method:
- zoo = (‘wolf’, ‘elephant’,'penguin’)
3. dictionary dict: Variable Assignment Method:
- d = {key1 : value1, key2 : value2 }
4. sequence: the list, tuples, and strings are all sequences.
(1) index OPERATOR: gets a character of an element or string in the list/tuples.
(2) slice OPERATOR: gets a slice of a sequence, continuous element/Character
(3) eg:
- name = ’swaroop’
- print ‘characters 0 is’, name[0] # ’s’
Index operator, similar to C #
- print ‘characters 1 to 3 is’, name[1:3]
'Wa 'slice operator, similar to the Substring method in C #
In fact, Python contains a lot of content. For example, Python is different from the traditional interpreted scripting language. It will be compiled into bytecode during the first execution, then run the code. NET's DLR is a bit similar to Java's virtual machine. In short, it is to convert code into a way closer to machine code, which can improve performance.