1. 使用内置的`type()`函数:
a = [1, 2, 3]
print(type(a)) 输出:
2. 使用NumPy库中的`numpy.ndarray`对象:
import numpy as np
a = np.array([1, 2, 3])
print(type(a)) 输出:
3. 使用列表推导式结合`type()`函数:
a = [1, 2, 3]
print([type(x) for x in a]) 输出: [
, , ]
4. 使用`numpy`的`dtype`属性:
import numpy as np
a = np.array([1, 2, 3])
print(a.dtype) 输出: int64
以上方法可以帮助你查看Python中数组(包括列表和NumPy数组)元素的类型。