亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么這個運行成功,輸出錯誤,我對比了一下,輸出沒錯啊

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
  • 參與學習       758382    人
  • 解答問題       8967    個

學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序

進入課程

為什么這個運行成功,輸出錯誤,我對比了一下,輸出沒錯啊

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號