相关疑难解决方法(0)

type()和isinstance()之间有什么区别?

这两个代码片段之间有什么区别?使用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)

python oop inheritance types

1163
推荐指数
6
解决办法
69万
查看次数

Python 2.x和3.x中输入命令之间的差异

好吧,所以我使用了很多输入命令,我明白在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)

我何时必须使用其中一个?

python text input python-3.x

5
推荐指数
1
解决办法
1801
查看次数

标签 统计

python ×2

inheritance ×1

input ×1

oop ×1

python-3.x ×1

text ×1

types ×1