python中基本数据类型

Python3 中有六个标准的数据类型:

  • Number(数字)
  • String(字符串)
  • List(列表)
  • Tuple(元组)
  • Set(集合)
  • Dictionary(字典)
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值