Basic data type:
>> Numbers and strings
List:
There is no concept of arrays in >>python, the closest concept to arrays is lists and Ganso, and lists are containers for storing a series of elements
>>> str = [' AB ', ' CD ', ' EF ', ' G ']>>> print (str[3]) g
>> Modify the contents of the list
>>> str = [' AB ', ' CD ', ' EF ', ' g ']>>> str[3] = ' gh ' >>> print (str) [' AB ', ' CD ', ' EF ', ' gh ']
Ganso:There is no concept of arrays in Python, the concept closest to arrays is the list and Ganso, Ganso is a container for storing a series of elements
>>> str = (' AB ', ' CD ', ' EF ', ' g ') >>> print (str[1]) CD
>> Read only cannot be modified
>>> str = (' AB ', ' CD ', ' EF ', ' g ') >>> ABC = str[2]>>> print (ABC) ef>>> str[0] = ' a ' Traceback (most recent): File "<pyshell#13>", line 1, in <module> str[0] = ' A ' TypeError: ' Tu Ple ' object does not support item assignment
Collection:
There are two main functions in the >>python collection:
>> Building Relationships
>>> a = set (' abcdef ') >>> B = Set (' abc ') >>> x = a&b #交集 >>> print (x) {' C ', ' A ', ' B '} >>> y = a|b #并集 >>> print (y) {' B ', ' e ', ' f ', ' C ', ' a ', ' d '}>>> z = A-a #差集 >>> print (z) {' F ', ' d ', ' e '}
>> Eliminate duplicate elements
>>> a = (' Abcdabcabc ') >>> new = Set (a) >>> print (new) {' C ', ' B ', ' A ', ' d '}
Dictionary:
Also known as an associative array, stored in the form of a key-value pair in {}
>>> dic = {' name ': ' Xiaoxiao ', ' age ': 1, ' City ': ' Beijing '}>>> print (DIC) {' Age ': 1, ' City ': ' Beijing ', ' Name ': ' Xiaoxiao '}>>> print (dic[' name ') Xiaoxiao
>> Adding a modified dictionary
>>> dic = {' name ': ' Xiaoxiao ', ' Age ':1}>>> print (DIC) {' Age ': 1, ' name ': ' Xiaoxiao '}>>> dic[' City "] = ' Beijing ' >>> print (DIC) {' Age ': 1, ' City ': ' Beijing ', ' name ': ' Xiaoxiao '}>>> dic[' age '] = 0> >> Print (DIC) {' age ': 0, ' city ': ' Beijing ', ' name ': ' Xiaoxiao '}
Data types for Python