Pythons __init__ method

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • This video tutorial looks at the use of the Python _init_ method used when writing classes from which objects are created and then initialized.

Komentáře • 67

  • @Lennardish
    @Lennardish Před 3 lety +3

    Just very good and clear. I am addicted here to this way of teaching :)

  • @lovemetwicetoday
    @lovemetwicetoday Před 2 lety +4

    John, you are a fantastic teacher! Like many others, I really struggled to understand self, and only ever really had a loose understanding of OOP. I just wanted to say a huge heartfelt thank you, because I started to question my ability and doubt my(self). As others have said, great use of diagrams to really hit home the concept. I'm going to keep watching your videos, and you've earned a sub from me. Hope you're keeping well :).

    • @johnphilipjones
      @johnphilipjones  Před 2 lety +3

      Thank you for your generous comments and kind words it is appreciated.
      Best wishes Phil

  • @indrishmo
    @indrishmo Před 7 lety +15

    Finally, a video that clearly explains how the __init__ method works! Thank you, JPJ. I 100% approve of all your visualisations - it definitely helps to not only understand what you're saying, but also it works as a useful model for the learner.

  • @subramaniantr2091
    @subramaniantr2091 Před 4 lety +2

    I have to say that you're unbelievably good and clear. You do know how to learn things the best way and have created classes in your mind about how to construct the knowledge hierarchy. Incredible. Thank you very much.

    • @johnphilipjones
      @johnphilipjones  Před 4 lety

      Thank you for your very generous comments it is appreciated. Please check out the supporting website:
      www.PythonByteSize.com
      Best wishes
      Phil

  • @lakeguy65616
    @lakeguy65616 Před 2 lety +1

    one of the best explanations I've ever seen...

  • @renderdreality
    @renderdreality Před 7 lety +7

    Your tutorials are so good. You take complex theories and break it down into real world examples. I am now learning Python, and your explanations are much clearer than the python.org information. Hats off to you and thank you for taking the time to make these tutorials.

  • @imtiyazhussain8873
    @imtiyazhussain8873 Před 7 lety +3

    I just want to say that to this day, your videos are having a substantial impact for people like me who are trying to learn! I'm entering year 11 and programming is something I thoroughly enjoy but I do get confused with all the different terminology thrown around without explanations. I really liked this video because of the diagram and visual cues, and it really consolidated my understanding of "instances" which you talked about a lot in this video. Thank you so much, you're amazing at teaching.

  • @davidbenn
    @davidbenn Před 7 lety +4

    Thanks John! I have been reading lots of tutorials on Python Classes and this is the one that finally made it click.

  • @cilo56
    @cilo56 Před 8 lety +19

    You are just awesome. You have an uncannily natural talent for teaching and communicating. Thank you so much for this great lesson.

    • @johnphilipjones
      @johnphilipjones  Před 8 lety +3

      Thank you for your positive comments.
      Best wishes
      Phil
      (John Philip Jones)

    • @dimitriosdesmos4699
      @dimitriosdesmos4699 Před 7 lety

      Can you please explain networking one day, i want to learn to hack and antihack

  • @rifleman542
    @rifleman542 Před 8 lety +25

    this is incredible, I have tears in my eyes that I finally understand it so well, thanks a million, please keep making more videos on python

    • @johnphilipjones
      @johnphilipjones  Před 8 lety +2

      Glad it helped check out the following website:
      www.pythonbytesize.com/
      Best wishes
      Phil
      (John Philip Jones)

  • @johntobin9404
    @johntobin9404 Před 3 lety +1

    The best teacher out there, hands down. This has finally helped me get my head around OOP. Thank you so much.

    • @johnphilipjones
      @johnphilipjones  Před 3 lety

      Thank you for your generous comments it is appreciated.
      Best wishes
      Phil

  • @goldenbaraka2487
    @goldenbaraka2487 Před 7 lety +4

    You happened to be savior..! am falling in love with programming now because of you. more videos please

  • @donzami
    @donzami Před 6 lety +2

    By far the best explanation of a constructor in python. Thank you so much.

  • @ZhuYiting612
    @ZhuYiting612 Před 4 lety +1

    thank you, you are explaining things in a clear way.

  • @ulfen69
    @ulfen69 Před 6 lety +2

    This video was perfect for me now.
    I have just learned a little about classes.
    This confirmed the parts I know , I learned a bit more and also got a deeper understanding
    Thank you for an excellent lesson about classes.

  • @Unwired9374
    @Unwired9374 Před 7 lety +4

    You're an excellent teacher. This is extremely helpful. Thank you!

  • @imadahmad104
    @imadahmad104 Před 7 lety +4

    You are amazing sir! I have been struggling with these concepts for couple of years.

  • @ahmedr.
    @ahmedr. Před 3 lety +1

    This class/object video course by John is what every coder needs to learn after the 101 .

  • @vtj808
    @vtj808 Před 7 lety +2

    You are phenomenal. PERIOD.

  • @manyblock4192
    @manyblock4192 Před 2 lety

    Wow this is what i looking for, visualize how it's works is easier to understand for me, finally I can understand it not only know

    • @johnphilipjones
      @johnphilipjones  Před 2 lety

      Glad the videos are helping. Thank you for the positive feedback. Best wishes Phil

  • @ko95
    @ko95 Před 4 lety +2

    thanks! walkthrough of how to initalize objects

  • @naveentoopran
    @naveentoopran Před 7 lety +2

    Excellent Tutorials

  • @john-junkarsan4671
    @john-junkarsan4671 Před 6 lety +2

    THUMB UP! CLEAR ENOUGH TEACHING!

  • @itsravimalhotra3
    @itsravimalhotra3 Před 6 lety +1

    Thank you so much. It was so easy explanation.

  • @mahimsd7645
    @mahimsd7645 Před 6 lety +1

    gr8 work ,.......
    Oscars for you

  • @keerthivasang1178
    @keerthivasang1178 Před 6 lety +1

    Nice Explanation Thanks lottt !!!!

  • @SusanAmberBruce
    @SusanAmberBruce Před 5 lety +2

    Still a valuable lesson to visit

  • @shahdmoataz2814
    @shahdmoataz2814 Před 4 lety +1

    you’re going to heaven, sir

  • @MaxGoddur
    @MaxGoddur Před 7 lety +2

    Why does 'self' require a unique 'id' when the object has a unique name? Sorry just scrolled down and saw your reply to this from another interested party.

  • @3killz
    @3killz Před 8 lety +2

    your videos are amazing

    • @johnphilipjones
      @johnphilipjones  Před 8 lety

      +3killz Thank you for your positive comment it is appreciated.
      Regards
      Phil
      (John Philip Jones)

  • @satishpandu7601
    @satishpandu7601 Před 4 lety

    Plz do more videos like this

    • @johnphilipjones
      @johnphilipjones  Před 4 lety +1

      Check out the supporting website www.PythonByteSize.com
      Best wishes Phil

  • @rochakdhakal1937
    @rochakdhakal1937 Před 5 lety +1

    Awesome

  • @jeuxdeau2009
    @jeuxdeau2009 Před 6 lety +1

    Amazingg

  • @mahimsd7645
    @mahimsd7645 Před 6 lety +2

    I will dream about Class today ,

  • @giorgibakuradze
    @giorgibakuradze Před 5 lety

    Hallow Mr Jones
    , I have a question about name "Rita Jones", I'm doing everything as here but the program writes it "Traceback (most recent call last):
    File "C:\Users\user\Desktop\gadaitane fleshkaze ori klikis shinaarsi.py", line 8, in
    account_holder=CurrentAccount("kako")
    TypeError: CurrentAccount() takes no arguments" What happened?

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      Without seeing the full code I cannot be sure. However, it looks like you are missing a formal parameter in the __init__ method. So the argument you are passing has no where to be stored in the method.

  • @ronny22
    @ronny22 Před 6 lety

    the self.name, where did the dot name part come from, is that a built in function that the self keyword can use and if so can the self keyword use others. maybe something like self.id or self.range etc.....

    • @johnphilipjones
      @johnphilipjones  Před 6 lety +1

      ‘self’ is not a reserved word in Python. However, it is common practice to use ‘self’ to help reference the attributes (data fields and methods) of instances (i.e. objects). You can use any word you like instead of ‘self’ but this would just confuse others that read your code.
      ‘self.name’ is an example of dot notation
      Dot notation ‘defines’ the following: to the right of the dot is the attribute being INVOKED (if the attribute is a method) and to the left of the dot is the name of the object that contains the method (which will have been defined in the class) on which the object is based.
      Dot notation can ALSO ‘define’ the following: to the right of the dot is the attribute being ACCESSED (if the attribute is a data field) and to the left of the dot is the name of the object that contains the data field (which will have been defined in the class) on which the object is based.
      So in the example in the video ‘self.name’ is defining a data field in the ‘CurrentAccount’ class. The field is named ‘name’ and ‘self’ refers to the specific instance (object) of the class ‘CurrentAccount’.
      The following videos look at dot notation, __init__ and self:
      www.pythonbytesize.com/video-python-class-members.html
      www.pythonbytesize.com/video-python-methods-and-self.html
      www.pythonbytesize.com/video-pythons-self-parameter.html
      Best wishes
      Phil

  • @renderdreality
    @renderdreality Před 7 lety

    I would be really curious to see you explain deep learning with python.

  • @srinidhiskanda754
    @srinidhiskanda754 Před 7 lety

    thank you, small doubt if the variable name is declared inside a method here (__init__()) how can be accessible outside this method i. e (u accessed in get_customer_name( )) does it violates global and local space.

    • @johnphilipjones
      @johnphilipjones  Před 7 lety +2

      All instances of the class have access to their own copy of the variables declared in __init__ via the self.variableName i.e. all the methods declared can 'see' the variable because of the use of self
      Regards
      Phil

  • @davidochieng1443
    @davidochieng1443 Před 2 lety

    Hey JPJ,
    Is there a book you would recommend to python learners?

    • @johnphilipjones
      @johnphilipjones  Před 2 lety

      Hello David
      I have been programming for many years and very rarely use textbooks. I do however frequently referred to the documentation associated with Python. The documentation can sometimes be too much for a beginner to the language. However there is often useful tutorials embedded within the documentation. The link below takes you to the Python documentation. When you arrive at the webpage you will note that there is a link to a Python tutorial.
      docs.python.org/3/
      Best wishes
      Phil
      (John Philip Jones)

  • @ElBarosan
    @ElBarosan Před 8 lety

    Sir I think that "self" from "self.name=customer_name" is unnecessary because my instance already knows it's id. All the variable are stored inside of instance object, why should i use self for those variables ? Why my getter have to return self.name, this make no sense for interpreter.

    • @johnphilipjones
      @johnphilipjones  Před 8 lety +8

      +Tom Sawyer If you did not use "self" then the other methods in the class would not know of its existence. Without the use of "self" the name would be a local variable in the __init__ method

  • @DieMasterMonkey
    @DieMasterMonkey Před 6 lety +1

    I like it! Err, actually I hate the language...but love the vid, thanks! :-)

  • @halgurdaziz159
    @halgurdaziz159 Před 7 lety

    Hello, John, I am wondering if you have any typescript tutorials?

    • @johnphilipjones
      @johnphilipjones  Před 7 lety

      Not at the moment. Once the video series is complete I will be releasing such material.
      Regards
      Phil
      (John Philip Jones)

  • @photodoor913
    @photodoor913 Před 5 lety

    Thank you for this video. I tried with your code and get the following error:
    TypeError: CurrentAccount() takes no arguments

    • @johnphilipjones
      @johnphilipjones  Před 5 lety +1

      Contact me on the following web page and we can arrange for you to send me your code and I will look into it.
      www.pythonbytesize.com/contact.html
      Best wishes
      Phil

  • @chadhanson3431
    @chadhanson3431 Před 3 lety

    Do you have a video scaling this? Obviously, in practice you probably have multiple owners of a current account. Somehow ghat should be saved to a database. No?

    • @johnphilipjones
      @johnphilipjones  Před 3 lety

      Every instance of the current account class will have its own ID.
      Consequently every instance (i.e. object) is independent of each other. They just happen to be based on the same class. So each instance can be separately stored in a database.
      Best wishes Phil

  • @FitLife6767
    @FitLife6767 Před 5 lety

    Why self is not called id?

    • @johnphilipjones
      @johnphilipjones  Před 5 lety +1

      It is convention to call it self. Although you can call it anything you want but best not as everybody follows this convention. However, do not call it id as this is the name of a function in Python.
      Best wishes
      Phil

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      When you declare methods in a class then an instance of the class (i.e. object) will only know of the 'existence' of the method if it is passed self (i.e. the id). If you forget to put in the self parameter the method will belong to the class but will not be available to the object.
      Best wishes
      Phil

  • @FitzForward
    @FitzForward Před 5 lety +1

    May I have your paypal email? I have learned more in one hour of watching your videos then I have In weeks spent in my college course.

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      Hello Ryan, Thank you for your positive comments. I am glad the videos are helping. The link below directs you to the supporting website where PayPal can be located:
      www.johnphilipjones.com/donate.html
      Best wishes
      Philip Jones