Python3 中有六个标准的数据类型:
import numpy as np # number string list tuple dict set # number: int(x) float(y) complex(x) complex(x,y) 实数部分为x,虚数部分为y arr = np.array([2, 3, 5, 8]) # 1维数组 print(arr) # [2 3 5 8] print(type(arr)) # <class 'numpy.ndarray'> print(arr.shape) # (4,) print(arr.size) # 4 mat = np.array([[1, 2, 3], [4, 5, 6]]) # 2维数组 print(mat) # [[0. 0. 0.] [0. 0. 0.]] print(mat.shape) # (2, 3) print(mat.size) # 6 print(type(mat)) # <class 'numpy.ndarray'> str1 = 'Hello World!' # str ''或“” print(str1) # Hello World! print(type(str1)) # <class 'str'> print(len(str1)) # 12 li = [1, 2, 3, 4] # list 元素可以修改 [] print(li) # [1, 2, 3, 4] print(type(li)) # <class 'list'> print(len(li)) # 4 set1 = {8, 2, 3, 5, 8} # set 无序的不重复元素序列 {} print(set1) # {8, 2, 3, 5} print(type(set1)) # <class 'set'> print(len(set1)) # 4 tup = (1, 'a', 'food', 23) # tuple 元素不可以修改 () print(tup) # (1, 'a', 'food', 23) print(type(tup)) # <class 'tuple'> print(len(tup)) # 4 dict1 = {'name': 'David', 'age': 30, 'sex': 'male'} # dict 可存储任意类型对象 {:} print(dict1) # {'name': 'David', 'age': 30, 'sex': 'male'} print(type(dict1)) # <class 'dict'> print(len(dict1)) # 3