🌐
Scaler
scaler.com › home › topics › what are the types of attributes in python?
What Are the Types of Attributes in Python? - Scaler Topics
March 22, 2024 - Note: We must know that all the attributes of the Python class can be invoked using the dir() function as well as the vars() function (It is discussed in detail in later sections). We have two types of attributes in Python namely- Class attribute and Instance attribute.
🌐
Real Python
realpython.com › ref › glossary › attribute
attribute | Python Glossary – Real Python
In Python, an attribute is a value ... defining characteristics or properties of an object and can be data attributes (variables) or method attributes (functions)....
Discussions

python - Attribute definition - Stack Overflow
According to the Python Language Reference, Attribute references, in the statement ... obj.name is an attribute reference, name is the attribute name, and the produced value is the attribute. Note that value is the attribute in this case because it was produced by the attribute reference, not because it is inherently related. For example, an attribute reference may produce a new value every time it is evaluated. The primary must evaluate to an object of a type ... More on stackoverflow.com
🌐 stackoverflow.com
Can someone explain "_" and "__" in python clearly for me ?
There is no inherent purpose, it's just convention. Python doesn't have real enforced scoping, it just assumes you know not to mess with things you're explicitly asked to not mess with. More on reddit.com
🌐 r/learnpython
49
109
January 17, 2022
Why use underscore class attributes?
The leading underscore is python's way of having a private property. It doesn't actually make it private, but it tells other people using your class that it is private and they shouldn't be using it directly. In this case, there is a getter (@property) but no setter. So basically the name is meant to be immutable and can only be set when the object is initialized. If you added a setter, you might have some kind of validation or processing when the property is set. If you had a getter and setting that simply get and set the "private" variable without doing anything else then it would be kind of pointless unless it was meant to be expanded later. More on reddit.com
🌐 r/learnpython
10
2
June 14, 2022
Any way to get ALL attributes of an object in python?
Which library is this, and how did you construct the object? More on reddit.com
🌐 r/learnpython
10
10
July 20, 2024
🌐
Built In
builtin.com › software-engineering-perspectives › python-attributes
Python Attributes: Class vs. Instance | Built In
Attributes can be class attributes (which belong within a class) or instance attributes (which belong to a specific object). There are two types of attributes in Python: class attributes and instance attributes.
🌐
Tutorialspoint
tutorialspoint.com › python › python_class_attributes.htm
Python - Class Attributes
The properties or variables defined inside a class are called as Attributes. An attribute provides information about the type of data a class contains. There are two types of attributes in Python namely instance attribute and class attribute.
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.8 documentation
Most of these attributes check the type of the assigned value: Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes. CPython implementation detail: CPython’s current implementation only supports function attributes on user-defined functions. Function attributes on built-in functions may be supported in the future.
🌐
Medium
medium.com › @shukufabayramzada › understanding-object-and-class-attributes-in-python-1da88bf1a9de
Understanding Object and Class Attributes in Python | by Shukufa Bayramzada | Medium
June 2, 2024 - At the heart of OOP are attributes — variables that hold data related to classes and objects. To master Python, it’s essential to understand the two primary types of attributes: class attributes and instance attributes.
🌐
Board Infinity
boardinfinity.com › blog › attributes-in-python
Attributes in Python | Board Infinity
November 4, 2023 - In python, attributes that are defined out of the method but inside the python class object are known as class attributes.
🌐
Real Python
realpython.com › lessons › class-and-instance-attributes
Class and Instance Attributes (Video) – Real Python
First off, properties are actually called attributes in Python. 02:59 There are two types of attributes: instance attributes and class attributes. Instance attributes are what we’ve seen before.
Published: March 22, 2019
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-attributes-class-vs-instance-explained
Python Attributes: Class Vs. Instance Explained - GeeksforGeeks
July 23, 2025 - In Python, attributes are properties associated with objects. They can be variables or methods that are defined within a class or an instance of a class. Understanding the difference between class and instance attributes is fundamental in object-oriented programming.
🌐
Medium
gokulapriyan.medium.com › understanding-python-class-components-attributes-methods-and-properties-explained-1b83402098ed
🔍 Understanding Python Class Components: Attributes, Methods, and Properties Explained” | by Gokulapriyan | Medium
September 26, 2024 - They store data and are accessible within the class and, depending on their visibility, outside the class as well. Attributes are of two types: Instance Attributes and Class Attributes.
🌐
freeCodeCamp
freecodecamp.org › news › python-attributes-class-and-instance-attribute-examples
Python Attributes – Class and Instance Attribute Examples
April 12, 2022 - When creating a class in Python, you'll usually create attributes that may be shared across every object of a class or attributes that will be unique to each object of the class. In this article, we'll see the difference between class attributes and ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › class-instance-attributes-python
Class and Instance Attributes in Python - GeeksforGeeks
vars() - This function displays the attribute of an instance in the form of an dictionary.
Published: September 5, 2024
🌐
W3Schools
w3schools.com › python › python_class_properties.asp
Python Class Properties
Properties are variables that belong to a class. They store data for each object created from the class.
Top answer
1 of 3
4

TLDR: The attribute is the value produced by looking up the attribute name.


According to the Python Language Reference, Attribute references, in the statement

value = obj.name

obj.name is an attribute reference, name is the attribute name, and the produced value is the attribute. Note that value is the attribute in this case because it was produced by the attribute reference, not because it is inherently related. For example, an attribute reference may produce a new value every time it is evaluated.

The primary must evaluate to an object of a type that supports attribute references, which most objects do. This object is then asked to produce the attribute whose name is the identifier. This production can be customized by overriding the __getattr__() method. If this attribute is not available, the exception AttributeError is raised. Otherwise, the type and value of the object produced is determined by the object. Multiple evaluations of the same attribute reference may yield different objects.

In an attribute assignment such as

obj.name = value

the value does not necessarily become the attribute. If the attribute name points to a data descriptor, value may be stored, modified or discarded.

2 of 3
1

First let's talk about general objects in Python. The documentation defines 3 characteristics for every object:

  • identity

    An object’s identity never changes once it has been created; you may think of it as the object’s address in memory.

  • type

    An object’s type determines the operations that the object supports (e.g., “does it have a length?”) and also defines the possible values for objects of that type. The type() function returns an object’s type (which is an object itself). Like its identity, an object’s type is also unchangeable.

  • value

    The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable.

Understanding objects means understanding types, but types are objects also. These TypeObjects are one of the most important structures in Python and define the basic functionality of an object. Specifically they implement the getattr and setattr functions.

The default behavior for this implementation is described here:

The default behavior for attribute access is to get, set, or delete the attribute from an object’s dictionary. For instance, a.x has a lookup chain starting with a.__dict__['x'], then type(a).__dict__['x'], and continuing through the base classes of type(a) excluding metaclasses. If the looked-up value is an object defining one of the descriptor methods, then Python may override the default behavior and invoke the descriptor method instead. [...]

the methods for an class or an instance which can overwrite the default behaviour are __get__, __set__ and __delete__.

The documentation for the __get__ method specifies:

This method should return the computed attribute value or raise an AttributeError exception.

Summarizing all the above, my formal definition for an attribute would be along the lines of:

  • attributes are objects with identity, type and value
  • they are owned by another object

Further reading:

https://docs.python.org/3/reference/datamodel.html

https://docs.python.org/3/c-api/typeobj.html

https://docs.python.org/3/howto/descriptor.html?highlight=descriptor

https://realpython.com/python-descriptors/

🌐
LinkedIn
linkedin.com › pulse › object-class-attributes-python-understanding-best-practices-denys
Object and Class Attributes in Python: Understanding the Differences and Best Practices
August 9, 2023 - Python allows using object attributes and class attributes to manage data within a class. Understanding the differences between these two types of attributes is crucial for writing clean, efficient, and maintainable code.
🌐
Medium
ramilouhibi.medium.com › introduction-2524b0bade9a
Introduction. A Python object has two types of… | by Rami Louhibi | Medium
July 17, 2021 - Introduction A Python object has two types of attributes: Class Attribute and Instance Attribute. What’s a class attribute? As the above example, class_attr is a class attribute and …
🌐
CodeRivers
coderivers.org › blog › python-attribute
Python Attributes: A Comprehensive Guide - CodeRivers
February 22, 2026 - Every object in Python can have attributes. For example, consider a simple class: class MyClass: def __init__(self): self.data = 42 obj = MyClass() Here, data is an attribute of the obj instance of the MyClass class. It's a way to store information within the object. Data Attributes: These are used to store data values. In the above example, data is a data attribute. They can hold various types of data such as integers, strings, lists, etc.
🌐
Python Academy
python-academy.org › course › attributes and methods
Attributes and methods — Interactive Python Course
Today we'll look at data shared by all objects of a class, defuse a classic __init__ trap, and teach objects to print and compare like proper values. The attributes that __init__ creates via self.name = ... are called instance attributes: each object gets its own value.
🌐
Alma Better
almabetter.com › bytes › tutorials › python › methods-and-attributes-in-python
Attributes and Methods in Python
February 29, 2024 - Methods are used to access and manipulate the information of a question. Attributes and methods in Python can be troublesome to oversee in case they need to be organized appropriately.
🌐
JustAnswer
justanswer.com › computer-programming › i2xkr-attributes-python.html
Understanding Attributes in Python: Expert Q&A
There are two kinds of valid attribute names: data attributes and methods. The other kind of instance attribute reference is a method. A method is a function that “belongs to” an object.