在TensorFlow中,我有两个常量节点:
>> node1 = tf.constant(3.0, tf.float32)
>> node2 = tf.constant(4.0)
当我在Jupyter Notebook中运行此图时,以下两个会话运行的返回类型不同:
^{pr2}$对于此操作,没有输出单元格:
^{3}$但当我以:
>> print(sess.run(node1)), print(sess.run(node2)) #prints 3.0 and on the next line, it prints 4.0, and it ALSO prints a tuple (None, None) in the output cell.
你正在创建一个元组
打印功能和其他功能一样。它不返回值,所以它返回None,通常不显示。在
但是,逗号运算符创建一个元组,jupyter显示返回值。在
写4,4会得到(4,4)。在
什么都不写,都不会导致你所看到的。在
如果您只想执行两个操作,请将它们分别放在各自的行中—逗号不适用于此。在
第二行有两个用逗号分隔的
print
语句。print
函数返回None
,Python REPL(read eval print loop)将忽略单个None
。但是,逗号创建了一个元组,即使它只包含None
值,它也不会被忽略。在如果要在一行上运行多个语句,请使用
;
而不是,
:相关问题 更多 >
编程相关推荐