Python Forum
How to create a varying qty of instances of a Class and name them?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create a varying qty of instances of a Class and name them?
#2
Quote:However if I don't know how many player objects I need as the number of players is dynamic, can I make a function which will create and name these player objects?
You can use a loop to create the needed quantity of player instances, these can be store in a list or a dictionary whichever is most suitable.
Reply


Messages In This Thread
RE: How to create Objects in Classes - by Yoriz - May-29-2020, 12:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How does this code create a class? Pedroski55 6 722 Apr-21-2024, 06:15 AM
Last Post: Gribouillis
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 1,078 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  Cannot convert the series to <class 'int'> when trying to create new dataframe column Mark17 3 8,817 Jan-20-2022, 05:15 PM
Last Post: deanhystad
  Accessing varying command line arguements Rakshan 3 2,154 Jul-28-2021, 03:18 PM
Last Post: snippsat
  Create Generator in the Class quest 1 2,216 Apr-15-2021, 03:30 PM
Last Post: jefsummers
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,150 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  Class Instances called in the wrong order IanIous 4 2,991 Mar-06-2020, 02:16 PM
Last Post: IanIous
  How to access class variable? instances vs class drSlump 5 3,512 Dec-11-2019, 06:26 PM
Last Post: Gribouillis
  Have two class instances affect one another The_Zookinator 3 2,418 Jun-26-2019, 06:56 PM
Last Post: The_Zookinator
  How I can create reference to member of the class instance? AlekseyPython 8 4,046 Dec-05-2018, 06:24 AM
Last Post: AlekseyPython

Forum Jump:

User Panel Messages

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