python 输出变量类型
时间: 2023-10-02 10:03:40 浏览: 43
可以使用type()函数来输出变量的类型。例如:
```python
a = 1
print(type(a)) # 输出:<class 'int'>
b = "hello"
print(type(b)) # 输出:<class 'str'>
c = True
print(type(c)) # 输出:<class 'bool'>
```
注意,type()函数返回的是一个type对象,而不是字符串。但是可以使用str()函数将其转换为字符串。例如:
```python
a = 1
print(str(type(a))) # 输出:<class 'int'>,转换为字符串
b = "hello"
print(str(type(b))) # 输出:<class 'str'>,转换为字符串
c = True
print(str(type(c))) # 输出:<class 'bool'>,转换为字符串
```
相关问题
Python输出变量类型
在Python中,使用`type()`函数来输出变量的类型。下面是一个示例:
```python
x = 10
(type(x)) # 输出:<class 'int'>
y = 3.14
print(type(y)) # 输出:<class 'float'>
z = "Hello"
print(type(z)) # 输出:<class 'str'>
```
python输出变量类型
可以使用`type()`函数输出变量类型。比如,如果想要输出变量x的类型,可以使用以下代码:
```
x = "Hello, World!"
print(type(x))
```
输出结果为:
```
<class 'str'>
```
这表明变量x的类型为字符串(str)。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)
![](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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)