# Classes - functions - first parameter

**URL:** <https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362>\
**Category:** Python\
**Created:** [November 7, 2021, 4:05pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362 "2021-11-07T16:05:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lt.Smith](https://avatars.discourse-cdn.com/v4/letter/l/3bc359/32.png) [@Lt.Smith](https://forum.codewithmosh.com/u/Lt.Smith)\
**Post date:** [November 7, 2021, 4:05pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362/1 "2021-11-07T16:05:13Z")

</div>

Hi all !  
How does abc.name, gets the name John , in the second function ?

class Person:  
def **init** (mysillyobject, name, age):  
mysillyobject.name = name  
mysillyobject.age = age

def myfunc(abc):  
print("Hello my name is " + abc.name)

p1 = Person(“John”, 36)  
p1.myfunc()

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://forum.codewithmosh.com/u/Paul)\
**Post date:** [November 7, 2021, 6:36pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362/2 "2021-11-07T18:36:30Z")

</div>

So first of all it should be `def __init__ (mysillyobjecct, name, age)`.

Normally when we declare classes, the first variable that a function takes (like ` __init__ ` or `myfunc` in this example) is a variable, or pointer, to itself. Convention is that this variable is called `self`. In this example you use two different names for `self`. In the constructure you use `mysillyobject` and in `myfunc` you use `abc`. Because both these functions are part of the same class, they refer to the same object, ie `self`. you can use different names in the different functinos but they all refer to `self`. The first variable in any class method will be `self`, no matter what you call it.

In other words, `mysillyobject.name` , which is declared in the constructor and therefore available in the entire class, is exactly the same as `abc.name`. The code should really be written as follows:

```auto
class Person:
    def __init__ (self, name, age):
        self.name = name
        self.age = age

    def myfunc(self):
        print("Hello my name is " + self.name)

p1 = Person("John", 36)
p1.myfunc()

```

Here you can see why it works. You just used different names for `self` in the different methods, but in this case it does not create different variables. They all refer to what we normally use as `self`.

Hope this helps!  
Paul

---

<div class="post-metadata">

**Author:** ![Lt.Smith](https://avatars.discourse-cdn.com/v4/letter/l/3bc359/32.png) [@Lt.Smith](https://forum.codewithmosh.com/u/Lt.Smith)\
**Post date:** [November 7, 2021, 6:57pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362/3 "2021-11-07T18:57:38Z")

</div>

So the first function or method like Mosh says is the constructor, is this right ? and no matter how many functions(methods) are in the class, they all refer to the same class?

---

<div class="post-metadata">

**Author:** ![Paul](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@Paul](https://forum.codewithmosh.com/u/Paul)\
**Post date:** [November 7, 2021, 6:58pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362/4 "2021-11-07T18:58:53Z")

</div>

Yes. That’s correct. All methods that are indented under the class declaration is part of that class. The method with the name ` __init__ ` is the constructor.

---

<div class="post-metadata">

**Author:** ![Lt.Smith](https://avatars.discourse-cdn.com/v4/letter/l/3bc359/32.png) [@Lt.Smith](https://forum.codewithmosh.com/u/Lt.Smith)\
**Post date:** [November 7, 2021, 7:01pm UTC](https://forum.codewithmosh.com/t/classes-functions-first-parameter/8362/5 "2021-11-07T19:01:40Z")

</div>

Finally something is clear, that’s a load of my mind. Thank you @Paul !!! 👍 🍺
