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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:36:05+00:00 2026-06-08T02:36:05+00:00

I am trying to understand how the methods of the class are called when

  • 0

I am trying to understand how the methods of the class are called when defined from outside of it. While I’ve found other threads addressing this issue, I haven’t found a very clear answer to my question, so I want to post it in a simple form.

Is defining a function outside of a class and calling it from the inside the same as defining it from the inside.

def my_func(self_class, arg):
    do something with arg
    return something

class MyClass:
    function = my_func

versus

class MyClass:
    def function(self, arg):
        do something with arg
        return something

and then calling it as

object = MyClass()
object.function(arg)

Thank you in advance.

  • 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-08T02:36:07+00:00Added an answer on June 8, 2026 at 2:36 am

    The two versions are completely equivalent (except that the first version also introduces my_func into the global namespace, of course, and the different name you used for the first parameter).

    Note that there are no “class methods” in your code – both definitions result in regular (instance) methods.

    A function definition results in the same function object regardless of whether it occurs at class or module level. Therefore, the assignment in the first version of the code lifts the function object into the class scope, and results in a completely equivalent class scope as the second version.

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

Sidebar

Related Questions

Trying to understand PNG format. Consider this PNG Image: The Image is taken from
I was trying to understand behavior of Extension methods of c# and found below
I am trying to understand the difference between 2 methods that have the same
Trying to understand Ruby a bit better, I ran into this code surfing the
Trying to understand the math of this code snippet. A token is provided which
I'm trying to understand what is the correct why to implement COM interfaces from
I know there are methods to prevent a class from being created on the
I'm trying to understand the Repository Pattern , while developing an ASP.NET MVC application
I'm trying to disable 2 observer methods of a class which is in a
I am trying to persist a large class called an Authorizer which holds a

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.