Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?
@sus304

n個のオブジェクトをリストで受け取って処理

More than 3 years have passed since last update.

個数が未知のインスタンスを一度に受け取ってメンバを扱いたかった。

ObjList.py
class object:
  def __init__(self, value):
    self.L = value

def integral(ObjList):
  L = 0.0
  for obj in ObjList:
    L += obj.L
  return L

def main():
  obj1 = object(2.0)
  obj2 = object(3.0)

  L = integral([obj1, obj2])
  print(L)

if __name__ == '__main__':
  main()

意外とすっきり書けた。
想定している用途はまた別だけど、ToDoリストやガントチャートの実装に使えそう。

3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
sus304

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
3
Help us understand the problem. What is going on with this article?