「python」リストの内包表記を使用する方法

書式
[式 for 変数名 in 配列名 (if 条件式)]
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
cft = [11,22,33,44]
res = [n * 2 for n in cft]
print (res)
# coding: utf-8 cft = [11,22,33,44] res = [n * 2 for n in cft] print (res)
# coding: utf-8

cft = [11,22,33,44]

res = [n * 2 for n in cft]

print (res) 

結果
[22, 44, 66, 88]

Python

Posted by arkgame