python - 为什么 type(x) 和 print(type(x) 在 python 中显示的结果略有不同?
问题描述
让
x = [1,2,3]
然后在ipython,我得到以下
> In [8]: type(x)
Out[8]: list
>
> In [9]: print(type(x))
<class 'list'>
为什么不 print(type(x))
只是打印列表,而不是额外的类的东西?
一个相关的问题是,如何显示输出
type of x is; list
print(' type of x is: ', type(x))
不这样做是因为我得到了额外的课程内容,例如
In [2]: print(' type of x is: ', type(x))
type of x is: <class 'list'>
解决方案
正如 pwxcoo 所说,这为Ipython
您做了一些额外的工作,请在普通的 python shell 中尝试它,除非您明确显示,否则它不会显示任何内容print()
。
推荐阅读
- pandas - 即使在本地 pyspark 中的小数据集上,toPandas() 也会失败
- c++ - 在我的代码中输出给出 08 的错误在哪里
- spring-boot - 如何将 Spring Boot Web 服务配置为仅在 localhost 或指定配置文件上可用?
- r - 二维类环面空间中的迁移矩阵:在 R 中创建迁移矩阵
- angular - PrimeNG 表无法很好地排序数据
- php - 将 Api/Json 复杂化到 PHP mysql
- r - 创建一个以采用不同行的值为条件的变量
- .net - 从 windowsazure.mediaservices 迁移到 Microsoft.Azure.Management.Media
- r - 用 R 中的 data.table 计算字数
- php - 为什么我不能将数据/图像添加到我的数据库但它说成功