>>> class new_class():
...   def __init__(self, number):
...     self.multi = int(number) * 2
...     self.str = str(number)
... 
>>> a = new_class(2)
>>> a.__dict__
{'multi': 4, 'str': '2'}
>>> a.__dict__.keys()
dict_keys(['multi', 'str'])

You may also find pprint helpful.

Answer from Roger Pate on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-a-list-of-class-attributes-in-python
How to Get a List of Class Attributes in Python? - GeeksforGeeks
July 12, 2025 - Another way of finding a list of attributes is by using the module inspect. This module provides a method called getmembers() that returns a list of class attributes and methods.
Discussions

Setting list as a class attribute
An attribute, like a variable, is simply holding a reference to a Python object, not the object itself. The object referenced can be any Python object including a new empty list object, which is what [] creates. Thus, when you have self.cars = [] in an instance method of a class, when the instance is created and the corresponding method is run (by default in the case of __init__) either a new attribute will be created for the instance referenced by self and assigned to reference a new list object, or the reference in an existing attribute will be replaced by a reference to the new list object (this would be in a different method from __init__). EDIT: Sorry, keyboard problems, kept submitting before I pressed finished. More on reddit.com
๐ŸŒ r/learnpython
4
3
March 11, 2024
Accessing attributes of a class
How do I access the attributes of a class, such as, __bases__, __name__, __qualname__? When I do this, class C: pass dir(C) then it gives me, ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', ... More on discuss.python.org
๐ŸŒ discuss.python.org
10
0
February 22, 2022
python - Getting attributes of a class - Stack Overflow
I want to get the attributes of a class, say: class MyClass(): a = "12" b = "34" def myfunc(self): return self.a using MyClass.__dict__ gives me a list of attributes and functions, and ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to access attributes of a class in a list that was made my iteration?
page_list[0].image would refer to whatever image is referencing in the 1st Page instance in the list. (I'm going with all lowercase here, as your post appears to have mixed cases which you probably didn't intend. Class would usually start with an uppercase, and variables/attributes are usually all lowercase.) PS. Code should perhaps be something like below: class Page: def __init__(self, image, other_stuff) self.image = image self.other_stuff = other def pdfloader(): pages = convert_from_bytes(path) for page in pages: page_list.append(Page(image = page, other_stuff = None)) page_list = [] somepath = Path.cwd() / 'somefolder' pdfloader(somepath) # iterate through list as required for page in page_list: process(page) # page would reference an instance of Page More on reddit.com
๐ŸŒ r/learnpython
1
1
July 24, 2023
People also ask

What happens if both instance attribute and class attribute are defined?
In that case, the instance namespace takes precedence over the class namespace. If there is an attribute with the same name in both, the instance namespace will be checked first and its value returned.
๐ŸŒ
toptal.com
toptal.com โ€บ python โ€บ python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptalยฎ
What is a Python namespace?
A Python namespace is a mapping from names to objects, with the property that there is zero relation between names in different namespaces. Namespaces are usually implemented as Python dictionaries, although this is abstracted away.
๐ŸŒ
toptal.com
toptal.com โ€บ python โ€บ python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptalยฎ
Python class method versus instance method: Whatโ€™s the difference?
In Python, a class method is a method that is invoked with the class as the context. This is often called a static method in other programming languages. An instance method, on the other hand, is invoked with an instance as the context.
๐ŸŒ
toptal.com
toptal.com โ€บ python โ€บ python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptalยฎ
๐ŸŒ
Mouse Vs Python
blog.pythonlibrary.org โ€บ home โ€บ how to get a list of class attributes in python
How to Get a List of Class Attributes in Python - Mouse Vs Python
January 31, 2020 - As most Python programmers should know, Python provides a handy little builtin called dir. I can use that on a class instance to get a list of all the attributes and methods of that class along with some inherited magic methods, such as โ€˜__delattr__โ€™, โ€˜__dict__โ€™, โ€˜__doc__โ€™, โ€˜__format__โ€™, etc.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python oop โ€บ python class attributes
Understanding Python Class Attributes By Practical Examples
November 13, 2020 - When you access an attribute via an instance of the class, Python searches for the attribute in the instance attribute list. If the instance attribute list doesnโ€™t have that attribute, Python continues looking up the attribute in the class attribute list.
๐ŸŒ
Net Informations
net-informations.com โ€บ python โ€บ iq โ€บ attributes.htm
How to Get a List of Class Attributes in Python
class MyClass: class_attr1 = 42 ... {'__module__': '__main__', 'class_attr1': 42, 'class_attr2': 'Hello', ...} The dir() function returns a list of valid attributes and methods for an object....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ setting list as a class attribute
r/learnpython on Reddit: Setting list as a class attribute
March 11, 2024 -

Hi!

I just finished a turtle crossing ( a.k.a. Frogger) game as part of an online bootcamp. It uses the turtle library.

I managed quite easily, but there is one point which I can't really wrap my head around.

So I am generating Car class objects in random lanes. In order to be able to move them, query them in loops, etc. One of the init attributes is

self.cars = [ ]

Hence adding them to a list where I can apply different methods on them.

I remembered this from a previous lesson (snake game) but I still don't fully understand how an attribute can be a list.

Can someone explain this to a beginner?

Find elsewhere
๐ŸŒ
Toptal
toptal.com โ€บ python โ€บ python-class-attributes-an-overly-thorough-guide
Python Class Attributes: An Overly Thorough Guide | Toptalยฎ
January 16, 2026 - This is no goodโ€”altering our Python class variable via one instance alters it for all the others! At the namespace level all instances of Service are accessing and modifying the same list in Service.__dict__ without making their own data attributes in their instance namespaces.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Accessing attributes of a class - Python Help - Discussions on Python.org
February 22, 2022 - How do I access the attributes of a class, such as, __bases__, __name__, __qualname__? When I do this, class C: pass dir(C) then it gives me, ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__'] h...
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ is-there-a-way-to-list-the-attributes-of-a-class-without-instantiating-an-object
How to List Python Class Attributes Without Creating an Instance โ€” pythontutorials.net
Use __dict__ for the fastest results (no external dependencies), and inspect for more control. Listing Python class attributes without creating an instance is straightforward with tools like dir(), __dict__, and the inspect module.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ class-instance-attributes-python
Class and Instance Attributes in Python - GeeksforGeeks
2. dir() - This function displays more attributes than vars function,as it is not limited to instance. It displays the class attributes as well. It also displays the attributes of its ancestor classes.
Published: September 5, 2024
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_class_attributes.htm
Python - Class Attributes
__bases__ โˆ’ A possibly empty tuple containing the base classes, in the order of their occurrence in the base class list. To access built-in class attributes in Python, we use the class name followed by a dot (.) and then attribute name.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-attributes-class-and-instance-attribute-examples
Python Attributes โ€“ Class and Instance Attribute Examples
April 12, 2022 - In summary, class attributes remain the same for every object and are defined outside the __init__() function. Instance attributes are somewhat dynamic because they can have different values in each object. Instance attributes are defined in the __init__() function. Happy coding! ... On DataCamp Introduction to Object-Oriented Programming in Python George Boorman 4.9 out of 5 stars (2,854) from 2,854 ratings 3h 3 hours Intermediate Certificate View course (opens in a new tab)
๐ŸŒ
Quora
quora.com โ€บ What-is-the-best-way-to-list-only-the-class-attributes-of-a-class-in-Python
What is the best way to list only the class attributes of a class in Python? - Quora
Answer (1 of 3): You can use vars(), which will return a dictionary with the class attributes. [code] class MyClass( ): def __init__(self): self.foo = 9 self.bar = 10 def class_attrs(self): return vars(self) c = MyClass() c.class_attrs() # ==> {'foo': 9, 'bar': 10} [/code] ED...
๐ŸŒ
Turing
turing.com โ€บ kb โ€บ introduction-to-python-class-attributes
A Guide to Python Class Attributes and Class Methods
Attributes are defined within a class and can be accessed and modified by both the class and its objects. In Python, class attributes are defined directly within the class definition and are shared among all instances of the class.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to access attributes of a class in a list that was made my iteration?
r/learnpython on Reddit: How to access attributes of a class in a list that was made my iteration?
July 24, 2023 -

I've had a lot of issues getting information into and out of a list of classes that I've generated by iteration. In my latest project, I'm using PDF2image to open a pdf and store each page in a list of classes as well as a few other attributes unique to each page. My problem is that I have a really loose grip on how to handle data coming in and out of functions and particularly classes. Like in the following:

'class page():

 def __init__(self, image, other_stuff)

      Self. Image = image

      Self. Other_stuff = other

Page_list = []

def pdfloader():

 Pages = convert_from_bytes(path)

 For page in pages:

      Page_list.append(page(image = page, other_stuff = None))

'

So like, in this example, I've appended 'page_list' with a new instance for each page that was pulled from the pdf and stored as an array. This works great. But now I have no idea how to access each instance to get the array, and then write 'other_stuff' to that instance.

(Also, sorry for the formatting, I'm writing this on mobile and I have to be in bed for work tomorrow. If it makes no sense, I'll take it down and re-post when I get the chance on desktop)

๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ python-attributes
Python Attributes: Class vs. Instance | Built In
Python attributes are variables or methods associated with an object that store data about the object's properties and behavior. Class attributes belong to a class, while instance attributes belong to a specific object and are unique to each object.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 74478676 โ€บ class-object-attributes-to-list-in-a-one-liner โ€บ 74478835
python - Class object attributes to list in a one liner - Stack Overflow
Something like my_new_list = [o.name for o in my_object_list]. ... @chepner That was exactly what I was looking for, would you post it as an answer? Then I could mark it as correct. ... Save this answer. ... Show activity on this post. this kind of things is made easy by the comprehension syntax in Python; ... Now, if one does not know at coding-time which attribute should be retrieved, the getattr built-in can be used to retrieve an attribute by name passed as a string:
๐ŸŒ
Enterprise DNA
blog.enterprisedna.co โ€บ python-get-all-attributes
Enterprise DNA: We Help Businesses Put Data and AI to Work
Learn data and AI skills on the platform, bring us in on a project, or run a managed Omni Command Centre. 220K+ professionals trained, 1,500+ companies impacted globally.
๐ŸŒ
Medium
medium.com โ€บ @euniceadewusic โ€บ understanding-class-and-instance-attributes-in-python-e3ae12eb3e66
Understanding Class and Instance Attributes in Python | by Eunice Adewusi | Medium
July 30, 2023 - It is defined inside the classโ€™s methods and is initialised for each object created from the class. Instance attributes represent the specific characteristics or state of individual objects. ... #!/usr/bin/python3 class Car: def __init__(self, color): self.color = color # 'color' is an instance attribute car1 = Car("red") car2 = Car("blue") print(car1.color) # Output: "red" print(car2.color) # Output: "blue"