为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这个运行成功,输出错误,我对比了一下,输出没错啊

print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c] 为什么这个运行成功,输出错误,我对比了一下,输出没错啊

正在回答

3 回答

这个是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'


0 回复 有任何疑惑可以回复我~

题目要求的是输出int型的值,你这个输出的是str,所以不满足题目的输出要求。

0 回复 有任何疑惑可以回复我~

the result is str not int ,so  no satisfy the question

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
初识Python
  • 参与学习       758620    人
  • 解答问题       8667    个

学python入门视频教程,让你快速入门并能编写简单的Python程序

进入课程

为什么这个运行成功,输出错误,我对比了一下,输出没错啊

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信