python 打印类型
时间: 2023-10-18 19:18:12 浏览: 22
在 Python 中,可以使用 `type()` 函数打印出变量或对象的类型。例如:
```python
x = 5
print(type(x)) # 输出 <class 'int'>
y = "hello"
print(type(y)) # 输出 <class 'str'>
z = [1, 2, 3]
print(type(z)) # 输出 <class 'list'>
```
其中,`<class 'int'>`、`<class 'str'>`、`<class 'list'>` 等是 Python 内置的类名,表示变量或对象的类型。
相关问题
python打印数据类型
在Python中,可以使用 `type()` 函数来打印数据类型。例如,如果你想要打印一个整数变量的数据类型,可以使用以下代码:
```python
x = 10
print(type(x))
```
输出结果为:
```
<class 'int'>
```
如果你想要打印一个字符串变量的数据类型,可以使用以下代码:
```python
s = "Hello, World!"
print(type(s))
```
输出结果为:
```
<class 'str'>
```
类似地,你可以使用 `type()` 函数来打印其他数据类型,如列表、字典、布尔值等。
python打印变量类型
在Python中,可以使用`type()`函数来获取变量的类型。下面是一些例子:
```python
x = 300
print(type(x)) # 输出:<class 'int'>
pi = 3.14159
print(type(pi)) # 输出:<class 'float'>
s = "python"
print(type(s)) # 输出:<class 'str'>
```
所以,根据上面的例子,我们可以看到,变量`x`的类型是`int`,变量`pi`的类型是`float`,变量`s`的类型是`str`。