課程
/后端開發
/Python
/初識Python
print [a + b + c for a in '123456789' for b in '0123456789' for c in '0123456789' if a==c] 為什么這個運行成功,輸出錯誤,我對比了一下,輸出沒錯啊
2017-10-17
源自:初識Python 10-4
正在回答
這個是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
? ? 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'
題目要求的是輸出int型的值,你這個輸出的是str,所以不滿足題目的輸出要求。
the result is str not int ,so ?no satisfy the question
舉報
學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-10-18
這個是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'
2017-10-17
題目要求的是輸出int型的值,你這個輸出的是str,所以不滿足題目的輸出要求。
2017-10-17
the result is str not int ,so ?no satisfy the question