没有括号打印不工作 (Python 2.7)
Print not working without parenthesis (Python 2.7)
当我 运行 下面的代码时,我得到 "Syntax Error: invalid syntax"。但是,如果我 运行 打印后带括号的代码,我会得到正确答案。
liczby = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527]
for x in liczby:
if x == 237:
break
if x % 2 == 0:
print x
我想补充一点,这不是我在这个笔记本中 运行 的唯一东西,我已经(除其他外)包含了一些包:
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
最后,我想补充一点,在新工作簿中一切正常。有人知道这是什么原因吗?
这是导致问题的原因:from __future__ import print_function
。
这意味着您正在将 new print_function 从 Python 3 导入 Python2.7。因此,需要括号。更多关于 future imports.
它不应该在没有括号的情况下打印,因为您正在从 python 3 from __future__ import print_function
导入打印语句
https://docs.python.org/2/library/functions.html#print
当我 运行 下面的代码时,我得到 "Syntax Error: invalid syntax"。但是,如果我 运行 打印后带括号的代码,我会得到正确答案。
liczby = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
743, 527]
for x in liczby:
if x == 237:
break
if x % 2 == 0:
print x
我想补充一点,这不是我在这个笔记本中 运行 的唯一东西,我已经(除其他外)包含了一些包:
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
最后,我想补充一点,在新工作簿中一切正常。有人知道这是什么原因吗?
这是导致问题的原因:from __future__ import print_function
。
这意味着您正在将 new print_function 从 Python 3 导入 Python2.7。因此,需要括号。更多关于 future imports.
它不应该在没有括号的情况下打印,因为您正在从 python 3 from __future__ import print_function
导入打印语句
https://docs.python.org/2/library/functions.html#print