为什么这个运行成功,输出错误,我对比了一下,输出没错啊
print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c] 为什么这个运行成功,输出错误,我对比了一下,输出没错啊
2017-10-17
这个是python2和python3里的区别
C:\WINDOWS\system32>python2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c]
['101', '111', '121', '131', '141', '151', '161', '171', '181', '191', '202', '212', '222', '232', '242', '252', '262', '272', '282', '292', '303', '313', '323', '333', '343', '353', '363', '373', '383', '393', '404', '414', '424', '434', '444', '454', '464', '474', '484', '494', '505', '515', '525', '535', '545', '555', '565', '575', '585', '595', '606', '616', '626', '636', '646', '656', '666', '676', '686', '696', '707', '717', '727', '737', '747', '757', '767', '777', '787', '797', '808', '818', '828', '838', '848', '858', '868', '878', '888', '898', '909', '919', '929', '939', '949', '959', '969', '979', '989', '999']
>>> exit()
File "<stdin>", line 1
exit()
^
SyntaxError: invalid syntax
>>> exit()
C:\WINDOWS\system32>python3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c]
File "<stdin>", line 1
print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c]
^
SyntaxError: Missing parentheses in call to 'print'
举报