If the function is inside a class (a method), write it like this:

def get_list_stores(self, code):

And you have to call it over an instance of the class:

ls = LeclercScraper()
ls.get_list_stores(92)

If it's outside a class, write it without the self parameter:

def get_list_stores(code):

Now it can be called as a normal function (notice that we're not calling the function over an instance, and it's no longer a method):

get_list_stores(92)
Answer from Óscar López on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › what is self parameter? and how do i run the function?
r/learnpython on Reddit: What is self parameter? and how do I run the function?
April 19, 2023 -

been doing leetcode and did a pivotindex questions:

how do I call the function that I have created? What are you suppose to enter for "self"?

pivotIndex(self, nums)

I understand nums is the list that the function is going to go through, but what am I suppose to enter for self?

nums = [1,7,3,6,5,6]

class solution:
    def pivotIndex(self, nums):
        leftsum = 0
        rightSum = sum(nums)
        for idx, ele in enumerate(nums):
            rightSum -= ele
            if leftsum == rightSum:
                return idx
            leftsum += ele
        return -1
Top answer
1 of 4
2
You should read about the basics for classes in Python: https://docs.python.org/3/tutorial/classes.html In short, "functions" in a class are called "methods" of a class object. The "self" is basically pointing to the object you created with the class, but don't write it out when calling a function. Here is a function without a class: def add_two(a): return a + 2 x = add_two(3) print(x) You just call it without any special requirements. Here is a "function" inside a class. class MyClass: def add_two(self, a): return a + 2 myobject = MyClass() x = myobject.add_two(3) print(x) Here is a lot of going on. First you create an object instance from the class. Then the object has all functions and attributes of the class. You can just use them with a dot in between the names. The self in this case represents the object that was created and is not used as an argument when calling the method/function. In your case you would do it like this: class solution: def pivotIndex(self, nums): leftsum = 0 rightSum = sum(nums) for idx, ele in enumerate(nums): rightSum -= ele if leftsum == rightSum: return idx leftsum += ele return -1 nums = [1,7,3,6,5,6] myobject = solution() output = myobject.pivotIndex(nums) print(output) Also you should use a class or function after it was defined, otherwise Python don't know it the moment you are calling it. Meaning, define all classes and functions on top of the script and on the bottom use them.
2 of 4
2
What are you suppose to enter for "self"? You don't need to enter anything. Python will always attempt to pass an object calling one of its methods to that method as the first argument, so we typically call that parameter self. This is made more confusing because leetcode requires all of its solutions, even ones that only demand a single method, to be wrapped in a class. You don't need to really worry about this until you get to actually learning object-oriented programming concepts. how do I call the function that I have created? You don't. The code that's testing your solution will call it for you.
Discussions

python - Call a function in it self? - Stack Overflow
There is no problem as long as there is a break condition, in other words the calls to itself stop at some point. Otherwise you have an infinite loop. ... Sign up to request clarification or add additional context in comments. ... Save this answer. Show activity on this post. The function will ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to call method with "self" parameter? - Stack Overflow
I need to call a function method complete_login: class VKOAuth2Adapter(OAuth2Adapter): ... def complete_login(self, request, app, token, **kwargs): ... It should be really easy, but i More on stackoverflow.com
🌐 stackoverflow.com
python - Use of self when calling functions within a class - Stack Overflow
I'm new to programming and can't quite grasp the formalism of classes. I have a file plots.py consisting of a class of functions: import numpy as np class SHO1D: def prob(T, x, N): i =... More on stackoverflow.com
🌐 stackoverflow.com
python - How to call a function within a class with self - Stack Overflow
Right now I keep getting either the error that self is not defined, or the error that foo expects 1 argument but 0 was provided. ... You can't, because that doesn't make any sense. If you want foo to be callable without a myClass instance, why is it an instance method? ... @Soumendra If the OP really wants to call the function ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 76085972 › python-class-call-method-self-argument-why-self
Python Class Call Method Self Argument - Why self? - Stack Overflow
Python Classes can have different types of functions, what you are describing are class and static methods. A class method requieres a class instance with a self variable: class MyClass: def __init__(self, value): self.value = value def get_value(self): return self.value # Create an instance of MyClass obj = MyClass(10) # Call the get_value method on the instance print(obj.get_value()) # Output: 10 ·
🌐
Python Morsels
pythonmorsels.com › what-is-self
Python's self - Python Morsels
December 28, 2020 - Python's self is really just a variable that points to the current instance of our class. Every method you define must accept self as its first argument.
🌐
Quora
quora.com › Why-do-we-need-to-pass-self-as-a-parameter-while-calling-a-class-function-Python
Why do we need to pass self as a parameter while calling a class function (Python)? - Quora
Answer (1 of 2): You don’t, but there is a lot of confusion in your question. Let me see if I can clear some things up. There are three kinds of methods in Python: 1. instance methods: these are declared in the definition of a class and have no decorator. They take self as a first parameter, bu...
🌐
GeeksforGeeks
geeksforgeeks.org › self-in-python-class
self in Python class - GeeksforGeeks
February 26, 2025 - In Python, an instance object is an individual object created from a class, which serves as a blueprint defining the attributes (data) and methods (functions) for the object. When we create an object from a class, it is referred to as an instance. Each instance has its own unique data but shares the ... Dynamic attributes in Python are terminologies for attributes that are defined at runtime, after creating the objects or instances. In Python we call all functions, methods also as an object.
🌐
Stack Overflow
stackoverflow.com › questions › 71055019 › call-a-function-in-it-self
python - Call a function in it self? - Stack Overflow
It is called recursion. A type of concept of function calling itself. If it has no proper if statement that terminates the function itself, loop will not end or it will error.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › self in python class
Self in Python Class - How to Use Self in Python? | Scaler Topics
February 9, 2024 - In Python classes, self serves as a reference to the current instance of the class. Let's illustrate this with a simple example: In this example, self refers to the current instance (obj1 or obj2) when display() method is called.
🌐
W3Schools
w3schools.com › python › python_class_self.asp
Python self Parameter
Without self, Python would not know which object's properties you want to access: The self parameter links the method to the specific object: class Person: def __init__(self, name): self.name = name def printname(self): print(self.name) p1 = Person("Tobias") p2 = Person("Linus") p1.printname() p2.printname() Try it Yourself » · It does not have to be named self, you can call it whatever you like, but it has to be the first parameter of any method in the class:
🌐
GeeksforGeeks
geeksforgeeks.org › python › self-in-python-class
self in Python - GeeksforGeeks
July 4, 2026 - Here, this is used instead of self. The program works correctly because Python does not require the parameter name to be self. However, using self is recommended because it is the standard convention. self parameter refers to the object that calls a method.
🌐
Stack Overflow
stackoverflow.com › questions › 63514386 › use-of-self-when-calling-functions-within-a-class
python - Use of self when calling functions within a class - Stack Overflow
To use it, put it as the first parameter in your function (which is inside the class). When calling the function (class().function()), the self parameter would be autofilled by Python, so you only need to fill in the original parameters.
🌐
Real Python
realpython.com › ref › glossary › self
self (argument) | Python Glossary – Real Python
In Python, self is a widely followed convention for naming the first argument in instance methods within a class. It represents the instance on which the method is being called, allowing access to instance attributes and methods.
🌐
Martin Heinz
martinheinz.dev › blog › 81
What is Python's "self" Argument, Anyway? | Martin Heinz | Personal Website & Blog
September 19, 2022 - To make it little easier to understand, let's demonstrate this by implementing a "method" using descriptor. First we create a pure-Python implementation of a function object: import types class Function: def __get__(self, instance, objtype=None): if instance is None: return self return types.MethodType(self, instance) def __call__(self): return
🌐
Programiz
programiz.com › article › python-self-why
self in Python, Demystified
The calling process is automatic while the receiving process is not (its explicit). This is the reason the first parameter of a function in class must be the object itself. Writing this parameter as self is merely a convention. It is not a keyword and has no special meaning in Python.
🌐
HubSpot
blog.hubspot.com › home › the hubspot website blog
The HubSpot Website Blog
November 22, 2022 - HubSpot’s Website Blog covers everything you need to know to build maintain your company’s website.
🌐
Medium
medium.com › @johnidouglasmarangon › using-call-method-to-invoke-class-instance-as-a-function-f61396145567
Using __call__ method to invoke class instance as a function | by Johni Douglas Marangon | Medium
August 23, 2022 - import json from urllib.request import urlopenclass Setting(object): def __init__(self, url): with urlopen(url) as content: self.config = json.load(content) def __call__(self, value): return self.config[value]settings = Setting("https://bit.ly/3ippyXa")db = settings("db") print(db) Decorator can be implemented with classes in Python, in this case the classes need to be called like a function.