使用Python中的type方法,但是显示不了结果
coding=utf-8
id = 1
type(id)
print id
class a:
pass
class b(a):
pass
isinstance(a(), a) # returns True
type(a()) == a # returns True
isinstance(b(), a) # returns True
type(b()) == a # returns False
使用Python中的type方法,但是显示不了结果
id = 1
type(id)
print id
class a:
pass
class b(a):
pass
isinstance(a(), a) # returns True
type(a()) == a # returns True
isinstance(b(), a) # returns True
type(b()) == a # returns False
命令行交互式你输入则解释一句,并直接输出运行结果。
脚本中则需要使用print
python 2 print type(id)
python 3 print(type(id))
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
1 回答3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
如果你当做py文件运行,那么自然需要添加print才会显示。比如
print(type(id))
。如果你在交互环境中,比如python IDE自带的python console中,则会自动调用repr方法,所以会显示输出。比如: