LoginSignup
4
5

More than 5 years have passed since last update.

Python 関数の引数に内包表記

Posted at

nums = [1,2,3]
sum(2*x for x in nums) 

と書けることを知らなかったのでメモ。

実際は

(2*x for x in nums) 

というジェネラータが作られ、関数に渡されているだけで、

sum((2*x for x in nums))

と同じ。

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5