-2

これは、エディターで編集し、シェルでコンパイルするコードです。
整数 19 を入力すると、c を出力しても、必要['1','9']なのではなくそのまま[1,9]です。Pythonファイルをコンパイルする代わりに、インタラクティブインタープリターでこれを試してみましたが、うまくいきました。

a = raw_input("Please enter a positive number ")    
c = []    
c = list(a)    
map(int, c) 
4

1 に答える 1

4

インプレースではないため、map出力をに再割り当てする必要がありますc

>>> a=raw_input("Please enter a positive number ")    
Please enter a positive number 19
>>> c = list(a) 
>>> c = map(int,c) # use the list() function if you are using Py3
>>> c
[1, 9]

ドキュメントを参照してくださいmap

関数を iterable のすべてのアイテムに適用し、結果のリストを返します

(私のものを強調)

于 2015-06-06T22:30:43.303 に答える