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 479159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:45:52+00:00 2026-05-13T00:45:52+00:00

Or is everything a method? Since everything is an object, a def whatever: is

  • 0

Or is everything a method?

Since everything is an object, a

def whatever:

is just a method of that file.py, right?

  • 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-05-13T00:45:53+00:00Added an answer on May 13, 2026 at 12:45 am

    Python has functions. As everything is an object functions are objects too.

    So, to use your example:

    >>> def whatever():
    ...     pass
    ...
    >>> whatever
    <function whatever at 0x00AF5F30>
    

    When we use def we have created an object which is a function. We can, for example, look at an attribute of the object:

    >>> whatever.func_name
    'whatever'
    

    In answer to your question – whatever() is not a method of file.py. It is better to think of it as a function object bound to the name whatever in the global namespace of file.py.

    >>> globals()
    {'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__d
    oc__': None, 'whatever': <function whatever at 0x00AF5EB0>}
    

    Or to look at it another way, there’s nothing stopping us from binding the name whatever to a different object altogether:

    >>> whatever
    <function whatever at 0x00AF5F30>
    >>> whatever = "string"
    >>> whatever
    'string'
    

    There are other ways to create function objects. For example, lambdas:

    >>> somelambda = lambda x: x * 2
    >>> somelambda
    <function <lambda> at 0x00AF5F30>
    

    A method is like attribute of an object that is a function. What makes it a method is that the methods get bound to the object. This causes the object to get passed to the function as the first argument which we normally call self.

    Let’s define a class SomeClass with a method somemethod and an instance someobject:

    >>> class SomeClass:
    ...     def somemethod(one="Not Passed", two="Not passed"):
    ...         print "one = %s\ntwo = %s" % (one,two)
    ...
    >>> someobject = SomeClass()
    

    Let’s look at somemethod as an attribute:

    >>> SomeClass.somemethod
    <unbound method SomeClass.somemethod>
    >>> someobject.somemethod
    <bound method SomeClass.somemethod of <__main__.SomeClass instance at 0x00AFE030
    

    We can see it’s a bound method on the object and an unbound method on the class. So now let’s call the method and see what happens:

    >>> someobject.somemethod("Hello world")
    one = <__main__.SomeClass instance at 0x00AFE030>
    two = Hello world
    

    As it’s a bound method the first argument received by somemethod is the object and the second argument is the first argument in the method call. Let’s call the method on the class:

    >>> SomeClass.somemethod("Hello world")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: unbound method somemethod() must be called with SomeClass instance as first argument (got str instance instead)
    

    Python complains because we’re trying to call the method without giving it an object of the appropriate type. So we can fix this by passing the object “by hand”:

    >>> SomeClass.somemethod(someobject,"Hello world")
    one = <__main__.SomeClass instance at 0x00AFE030>
    two = Hello world
    

    You might use method calls of this type – calling a method on a class – when you want to call a specific method from a superclass.

    (It is possible to take a function and bind it to class to make it a method, but this is not something that you’d normally ever need to do.)

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

Sidebar

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.