这两个代码片段之间有什么区别?使用type():
import types
if type(a) is types.DictType:
do_something()
if type(b) in types.StringTypes:
do_something_else()
Run Code Online (Sandbox Code Playgroud)
使用isinstance():
if isinstance(a, dict):
do_something()
if isinstance(b, str) or isinstance(b, unicode):
do_something_else()
Run Code Online (Sandbox Code Playgroud) 好吧,所以我使用了很多输入命令,我明白在Python2中我可以这样做:
text = raw_input ('Text here')
Run Code Online (Sandbox Code Playgroud)
但是现在我使用Python 3,我想知道它们之间有什么区别:
text = input('Text here')
Run Code Online (Sandbox Code Playgroud)
和:
text = eval(input('Text here'))
Run Code Online (Sandbox Code Playgroud)
我何时必须使用其中一个?