Skip to content

Instantly share code, notes, and snippets.

@justinchuby
Created March 15, 2023 15:51
Show Gist options
  • Save justinchuby/dbe99ce7ddbebb92d5d453f34afd3fa5 to your computer and use it in GitHub Desktop.
Save justinchuby/dbe99ce7ddbebb92d5d453f34afd3fa5 to your computer and use it in GitHub Desktop.
Python passes in self to its methods as the first argument
In [3]: def foo(*a): print(a)
In [4]: class Test:
...: func = foo
...: def bar(self):
...: self.func(42)
...:
In [5]: Test().bar()
(<__main__.Test object at 0x106751ab0>, 42)
@justinchuby
Copy link
Author

@BowenBao
Copy link

https://gist.github.com/BowenBao/e186816b754a036c74966d92e675af25 @justinchuby

It looks like only class variable case is treated as 'method'.

@justinchuby
Copy link
Author

Looks like it. That's good learning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment