Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:07:52+00:00 2026-06-17T07:07:52+00:00

I am trying to verify the difference between instance attributes and class attributes as

  • 0

I am trying to verify the difference between instance attributes and class attributes as laid out by the Python tutorial release 2.7.3 dated Nov 01, 2012, chapter 9: Classes, Page 66 last line (source):

Valid method names of an instance object depend on its class. By
definition, all attributes of a class that are function objects define
corresponding methods of its instances. So in our example, x.f is a
valid method reference, since MyClass.f is a function, but x.i is not,
since MyClass.i is not. But x.f is not the same thing as MyClass.f —
it is a method object, not a function object.

I have this:

class MyClass:    
   """A simple example class"""    
   i = 12345   
   def f():    
      return 'hello world'

Then I do this:

>>> x = MyClass()
>>> x.f
<bound method MyClass.f of <__main__.MyClass instance at 0x02BB8968>>
>>> MyClass.f
<unbound method MyClass.f>
>>> type(MyClass.f)
<type 'instancemethod'>
>>> type(x.f)
<type 'instancemethod'>

Note that the type of both x.f and MyClass.f is instancemethod. There is no difference in types but the tutorial says otherwise. Can someone please clarify?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:07:55+00:00Added an answer on June 17, 2026 at 7:07 am

    Bound vs Unbound Methods – an explanation.

    … or why Python has the behaviour you point out.

    So, first off, a note that this is different in 3.x. In 3.x, you will get MyClass.f being a function, and x.f as a method – as expected. This behaviour is essentially a poor design decision that has later been changed.

    The reason for this is that Python has the concept of a method that is different to most languages, which is essentially a function with the first argument pre-filled as the instance (self). This pre-filling makes a bound method.

    >>> x.foo
    <bound method MyClass.foo of <__main__.MyClass instance at 0x1004989e0>>
    

    In Python 2.x and before, it was reasoned that a method not attached to an instance would be an unbound method, which was a function with the restriction that the first argument (self), must be an instance of the object. This is then ready to be bound to an instance and become a bound method.

    >>> MyClass.foo
    <unbound method MyClass.foo>
    

    With time, it became clear an unbound method is really just a function with this odd restriction that didn’t really matter (that self must be of the ‘correct’ type), so they were removed from the language (in 3.x). This is essentially duck-typing self, which suits the language.

    Python 3.3.0 (default, Dec  4 2012, 00:30:24) 
    >>> x.foo
    <bound method MyClass.foo of <__main__.MyClass object at 0x100858ed0>>
    >>> MyClass.foo
    <function MyClass.foo at 0x10084f9e0>
    

    Further reading.

    This is a (condensed, from memory) explanation which can be read in full from Python creator Guido van Rossum’s own mouth in his ‘History of Python’ series.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to verify to myself, that C# Equals for IEnumerables is a reference
I'm trying to verify I understand Core Data relationships and/or possibly how to handle
I am trying to verify the content of a large list using Robotium, and
I am trying to verify whether an object is null or not, using this
I'm trying to verify on the fly generated bytecode! I already had several attempts,
Using the elementtree package in nodejs, I'm trying to verify the existence of a
I'm trying to create a UnitTest to verify that an object has been deleted.
I'm trying to get it to verify that it has the same item in
I'm trying to use mock to verify that an index property has been set.
I'm trying to use JPF to verify my bytecode generated while runtime with javassist.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.