Pythonのお勉強 Part 27
■ このスレッドは過去ログ倉庫に格納されています
0431デフォルトの名無しさん
2008/07/05(土) 13:18:51>>> map(str, L) #=>['1', '2', '3']
>>> L=[1,1.2,2,3]
>>> map(str, L) #=>['1', '1.2', '2', '3']
型変換<数値:文字列>は問題なし
>>> strL=['1','2','3']
>>> map(int, strL) #=>[1, 2, 3]
>>> strL=['1','1.2','2','3']
>>> map(int, strL)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.2'
型変換<文字列:数値>でこける
types とかインポートしてやらないと無理なのかな?
■ このスレッドは過去ログ倉庫に格納されています