Python 如何在Jupyter笔记本中获得多个正确/错误答案行?

Python 如何在Jupyter笔记本中获得多个正确/错误答案行?,python,jupyter-notebook,Python,Jupyter Notebook,一个有3行的单元格,如下所示: print(1) print(2) print(3) a = 5; b = 4.5; c = 'house' isinstance(a, (str)) isinstance(b, (str)) isinstance(c, (str)) 返回: 1 2 3 True 一个有4条线的细胞,如下所示: print(1) print(2) print(3) a = 5; b = 4.5; c = 'house' isinstance(a, (

一个有3行的单元格,如下所示:

print(1)

print(2)

print(3)
a = 5; b = 4.5; c = 'house'

isinstance(a, (str))

isinstance(b, (str))

isinstance(c, (str))
返回:

1

2

3
True
一个有4条线的细胞,如下所示:

print(1)

print(2)

print(3)
a = 5; b = 4.5; c = 'house'

isinstance(a, (str))

isinstance(b, (str))

isinstance(c, (str))
返回:

1

2

3
True
而不是:

False

False

True

为什么以及有没有办法在每一行上得到正确/错误的答案?

您必须打印变量,因为
isinstance
实际上不打印。
True
打印只是预览,而不是实际打印

因此,您必须使用:

a = 5; b = 4.5; c = 'house'

print(isinstance(a, (str)))

print(isinstance(b, (str)))

print(isinstance(c, (str)))
返回:

False
False
True

我相信Python的工作方式是,它按顺序计算每条语句,并在生成结果后停止。在您的情况下,
True
是第一个结果。所以Python把它放出来并停止。以后,请在问问题之前说明你做了什么。