Python Forum
How do I sum instance attributes?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I sum instance attributes?
#1
Say I have a bunch of instances of a class and one of the attributes below is the salary for every player. How would I calculate the sum of the salary for all players every time an instance is created?

Player1 = Player('John Smith','RB',749912,23)
Player2 = Player('Ron Ward', 'TE', 7000000, 26)
Player3 = Player('Matt Abrams','QB', 27525000, 30)
Player4 = Player('Anthony Atlee', 'LT', 11050000, 30)
Reply


Messages In This Thread
How do I sum instance attributes? - by pythonprogrammer - Jul-16-2019, 03:33 AM
RE: How do I sum instance attributes? - by Yoriz - Jul-18-2019, 05:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to add class instance attributes from list 999masks 2 2,757 Jul-22-2019, 07:59 AM
Last Post: 999masks
  Class object instance. Link instance attribute to class. Can it be done easier. Windspar 7 4,223 Dec-03-2018, 11:16 PM
Last Post: Windspar
  How to check if class instance exists in a list of class instance objects? sonicblind 23 20,482 May-27-2018, 05:44 AM
Last Post: buran
  Newbie here - how do i compare\check 2 attributes of an instance BenSalem 2 3,230 Aug-01-2017, 02:42 PM
Last Post: ichabod801
  Python3x running only with one instance (how can I prevent too many running instance) harun2525 5 18,320 Jul-21-2017, 07:36 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020