python 查看数据类型
时间: 2023-10-16 13:14:50 浏览: 24
可以使用type()函数查看数据类型,例如:
```python
a = 10
print(type(a)) # <class 'int'>
b = 3.14
print(type(b)) # <class 'float'>
c = 'hello'
print(type(c)) # <class 'str'>
d = [1, 2, 3]
print(type(d)) # <class 'list'>
e = {'name': 'Tom', 'age': 18}
print(type(e)) # <class 'dict'>
f = True
print(type(f)) # <class 'bool'>
```
输出结果分别为int、float、str、list、dict、bool等数据类型。
相关问题
python查看数据类型
在 Python 中,可以使用 `type()` 函数查看数据类型。例如,要查看变量 `x` 的数据类型,可以执行以下代码:
```python
x = 10
print(type(x))
```
输出结果为:
```
<class 'int'>
```
这表示变量 `x` 的数据类型是整数类型(int)。同样的方法也可以用于查看其他数据类型,如字符串(str)、浮点数(float)、列表(list)等。
python查看数据类型代码
要查看Python中的数据类型,可以使用`type()`函数。以下是一个示例代码:
```python
data = 10
print(type(data)) # 查看整数类型
data = 3.14
print(type(data)) # 查看浮点数类型
data = "Hello, world!"
print(type(data)) # 查看字符串类型
data = [1, 2, 3]
print(type(data)) # 查看列表类型
data = {"name": "John", "age": 30}
print(type(data)) # 查看字典类型
data = True
print(type(data)) # 查看布尔类型
```
运行以上代码,将会输出各个变量的数据类型。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)