Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

list of class instances in python

# Python3 code here creating class
class geeks:
	def __init__(self, name, roll):
		self.name = name
		self.roll = roll

# creating list	
list = []

# appending instances to list
list.append( geeks('Akash', 2) )
list.append( geeks('Deependra', 40) )
list.append( geeks('Reaper', 44) )

for obj in list:
	print( obj.name, obj.roll, sep =' ' )

# We can also access instances attributes
# as list[0].name, list[0].roll and so on.
Comment

PREVIOUS NEXT
Code Example
Python :: python forward declaration 
Python :: beautifulsoup - extracting link, text, and title within child div 
Python :: How can I make portable python desktop application 
Python :: lda from scratch implementation on iris python 
Python :: list[:] 
Python :: python random number between 1000 and 9999 
Python :: genisim 4.0 words 
Python :: write an empty block python 
Python :: python code sample submission of codeforces 
Python :: pyxl activate sheet 
Python :: update table odoo13 
Python :: Flask_SQLAlchemy is claiming my value is not boolean 
Python :: docstring python pycharm 
Python :: variable bound to set python 
Python :: Retry function for sending data 
Python :: python for loop skip iteration if condition not met jinja 
Python :: ring Delete Item From List 
Python :: swagger django 
Python :: send whats app message using python 
Python :: equivalent of geom smooth function in python using plotline lib 
Python :: Start of my python career 
Python :: python 2nd order ode 
Python :: funtools rougly equivalent to, internal 
Python :: python if not explaned 
Python :: dataflair python 
Python :: discord.py reply to message 
Python :: File C:Users7shalPycharmProjectsItsa Me Malariomain.py, line 2 from pygame.locals import import ^ SyntaxError: invalid syntax 
Python :: gizeh python 
Python :: pandas exploring dataframe 
Python :: django celery email 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =