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 :).
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.
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.
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.
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.
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.
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.
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?
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.
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.....
‘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
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.
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
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)
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.
+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
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
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?
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
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
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
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
Just very good and clear. I am addicted here to this way of teaching :)
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 :).
Thank you for your generous comments and kind words it is appreciated.
Best wishes Phil
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.
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.
Thank you for your very generous comments it is appreciated. Please check out the supporting website:
www.PythonByteSize.com
Best wishes
Phil
one of the best explanations I've ever seen...
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.
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.
Thanks John! I have been reading lots of tutorials on Python Classes and this is the one that finally made it click.
You are just awesome. You have an uncannily natural talent for teaching and communicating. Thank you so much for this great lesson.
Thank you for your positive comments.
Best wishes
Phil
(John Philip Jones)
Can you please explain networking one day, i want to learn to hack and antihack
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
Glad it helped check out the following website:
www.pythonbytesize.com/
Best wishes
Phil
(John Philip Jones)
The best teacher out there, hands down. This has finally helped me get my head around OOP. Thank you so much.
Thank you for your generous comments it is appreciated.
Best wishes
Phil
You happened to be savior..! am falling in love with programming now because of you. more videos please
By far the best explanation of a constructor in python. Thank you so much.
thank you, you are explaining things in a clear way.
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.
You're an excellent teacher. This is extremely helpful. Thank you!
You are amazing sir! I have been struggling with these concepts for couple of years.
This class/object video course by John is what every coder needs to learn after the 101 .
You are phenomenal. PERIOD.
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
Glad the videos are helping. Thank you for the positive feedback. Best wishes Phil
thanks! walkthrough of how to initalize objects
Excellent Tutorials
THUMB UP! CLEAR ENOUGH TEACHING!
Thank you so much. It was so easy explanation.
gr8 work ,.......
Oscars for you
Nice Explanation Thanks lottt !!!!
Still a valuable lesson to visit
you’re going to heaven, sir
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.
your videos are amazing
+3killz Thank you for your positive comment it is appreciated.
Regards
Phil
(John Philip Jones)
Plz do more videos like this
Check out the supporting website www.PythonByteSize.com
Best wishes Phil
Awesome
Amazingg
I will dream about Class today ,
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?
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.
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.....
‘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
I would be really curious to see you explain deep learning with python.
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.
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
Hey JPJ,
Is there a book you would recommend to python learners?
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)
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.
+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
I like it! Err, actually I hate the language...but love the vid, thanks! :-)
Hello, John, I am wondering if you have any typescript tutorials?
Not at the moment. Once the video series is complete I will be releasing such material.
Regards
Phil
(John Philip Jones)
Thank you for this video. I tried with your code and get the following error:
TypeError: CurrentAccount() takes no arguments
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
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?
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
Why self is not called id?
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
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
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.
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