Looks at instance variables of a Python object and in the process discusses the scope of an instance variable. It also considers the use of the self parameter and its role in setting up instance variables.
If we can use other words instead "self" as a parameter, then why a parameter in one of previous videos where value was sent as only parameter was recognized as TypeError. (I really appreciate and grateful for your videos and explanations. I have learnt a lot especially with tkinter framework from your videos)
>>> c = int(8) >>> print(c) 8 In the above example which is an instance of int class we are able to print the value assigned to 'a' without using any method. However, in the below example based on this vidoe print option does not display the value directly and we have to use method to access the value. What I have understand is that not all the class built restrict the access to data using method. >>> class a: def __init__(self,value): self.value = value self.double = self.value*2 def getvalue(self): return self.value def getdoubled(self): return self.double >>> b = a(9) >>> print(b) >>> print(b.getvalue()) 9
I developed a video to show getter and setter methods to match the style of other object orientated languages and UML collaboration diagrams. Python does not hide data in the same way as other programming languages. This topic area is something I will eventually make a video on. This will involve looking at Python decorators. Best wishes Phil
John, in your final words in each video you speak about joining a "circle" that relates to the videos. Unfortunately I could not quite understand what circle you are talking about. English is not my native tongue as I am from the continent ( The Netherlands :)
Hello Paul, It is referring to a Google+ circle but unfortunately Google shut down Google+. I now use Twitter to announce a release of a video. You can find me on Twitter at: @jpjVideoTuts Best wishes Phil
Hello, I enjoy your videos very much. My question when a instance object is created in the execution space, why does each object have the methods(code)? Why not just a pointer to the code? The code for all instances of the class is the same, only the attributes are different. Am I wrong?
This is a good question. The model I have devised is based on the unified modelling language notably the collaboration diagram. System design works on the assumption that all objects are independent of each other and have their own methods and data attributes. My approach in these videos allows the code to be consistent with the design of software systems. With respect to how Python implements it under the bonnet is important. However I would argue that viewing it from the perspective of software system design is more important. Best wishes Phil
@@johnphilipjones I think your videos are the best Python videos on You Tube. I am an old assembly language programmer and it was normal to pass a register containing the address of the data to a subroutine that processed each case. I agree with you just had a thought .... Phil
Thank you very much for the time you invest in transferring knowledge.. I have a brief question ? Given that you've made a class here CurrentAccount and the instance too, why it's impossible with print (dir. (account_holder)) to access instanc method it already shows an error in the program. You hope you understand my question. Thanks in advance
Hello Armin Gal, I am not quite sure what you are asking here but have a look at this video and get back to me if it does not clear up your question: czcams.com/video/bOt1ilhZ3tk/video.html Best wishes Phil
Thank you but you know when it says def __init__ how is that used in a class and why do you use it cant you just make the object and have several other functions with that. It may sound confusing but i just mean whats the point like remember how you said once that the instance is tied with an object. Whats the difference between that and making another function.
can you also explain what you mean by self.name i thought that self was just a parameter in a function so that it can communicate with other functions.
andre joseph Covered in these videos www.pythonbytesize.com/video-python-methods-and-self.html www.pythonbytesize.com/video-pythons-self-parameter.html www.pythonbytesize.com/video-python-method-parameters-and-self.html www.pythonbytesize.com/video-a-python-instance-method.html www.pythonbytesize.com/video-pythons-__init__-method.html www.pythonbytesize.com/video-python-instance-variables.html Best wishes Phil
John Philips Jones, You are a great teacher
Wonderful...simple and clear, with just enough repetition to help it sink in.
thanks again.
Your videos are really great. Thanks for doing these.
Thanks!
Thx !!!!!!!!!!!
If we can use other words instead "self" as a parameter, then why a parameter in one of previous videos where value was sent as only parameter was recognized as TypeError. (I really appreciate and grateful for your videos and explanations. I have learnt a lot especially with tkinter framework from your videos)
Thank you for your positive comments. Can you let me know which video you are referring to so I can answer your question.
Best wishes Phil
Thanks, This helped me a lot!
>>> c = int(8)
>>> print(c)
8
In the above example which is an instance of int class we are able to print the value assigned to 'a' without using any method. However, in the below example based on this vidoe print option does not display the value directly and we have to use method to access the value.
What I have understand is that not all the class built restrict the access to data using method.
>>> class a:
def __init__(self,value):
self.value = value
self.double = self.value*2
def getvalue(self):
return self.value
def getdoubled(self):
return self.double
>>> b = a(9)
>>> print(b)
>>> print(b.getvalue())
9
I developed a video to show getter and setter methods to match the style of other object orientated languages and UML collaboration diagrams. Python does not hide data in the same way as other programming languages. This topic area is something I will eventually make a video on. This will involve looking at Python decorators.
Best wishes
Phil
@@johnphilipjones Thanks John❤. I have watched that video on getter and setter after I had sent you my queries. Thank you so much.
John, in your final words in each video you speak about joining a "circle" that relates to the videos. Unfortunately I could not quite understand what circle you are talking about. English is not my native tongue as I am from the continent ( The Netherlands :)
Hello Paul,
It is referring to a Google+ circle but unfortunately Google shut down Google+.
I now use Twitter to announce a release of a video. You can find me on Twitter at: @jpjVideoTuts
Best wishes Phil
Hello, I enjoy your videos very much. My question when a instance object is created in the execution space, why does each object have the methods(code)? Why not just a pointer to the code? The code for all instances of the class is the same, only the attributes are different. Am I wrong?
This is a good question.
The model I have devised is based on the unified modelling language notably the collaboration diagram.
System design works on the assumption that all objects are independent of each other and have their own methods and data attributes.
My approach in these videos allows the code to be consistent with the design of software systems.
With respect to how Python implements it under the bonnet is important.
However I would argue that viewing it from the perspective of software system design is more important.
Best wishes
Phil
@@johnphilipjones I think your videos are the best Python videos on You Tube.
I am an old assembly language programmer and it was normal to
pass a register containing the address of the data to a subroutine that processed each case.
I agree with you just had a thought .... Phil
Thank you very much for the time you invest in transferring knowledge.. I have a brief question ? Given that you've made a class here CurrentAccount and the instance too, why it's impossible with print (dir. (account_holder)) to access instanc method it already shows an error in the program. You hope you understand my question. Thanks in advance
Hello Armin Gal,
I am not quite sure what you are asking here but have a look at this video and get back to me if it does not clear up your question:
czcams.com/video/bOt1ilhZ3tk/video.html
Best wishes
Phil
But what is the difference with making an object and an instance
An object is an instance of a class so there is no difference.
Regards
Phil
Thank you but you know when it says def __init__ how is that used in a class and why do you use it cant you just make the object and have several other functions with that. It may sound confusing but i just mean whats the point like remember how you said once that the instance is tied with an object. Whats the difference between that and making another function.
can you also explain what you mean by self.name i thought that self was just a parameter in a function so that it can communicate with other functions.
andre joseph Covered in these videos www.pythonbytesize.com/video-python-methods-and-self.html
www.pythonbytesize.com/video-pythons-self-parameter.html
www.pythonbytesize.com/video-python-method-parameters-and-self.html
www.pythonbytesize.com/video-a-python-instance-method.html
www.pythonbytesize.com/video-pythons-__init__-method.html
www.pythonbytesize.com/video-python-instance-variables.html
Best wishes
Phil
wow thank you but i was just looking over and I understand now thank you very much.
Object vs instance ???
An instance of a class is also referred to as an object.
Best wishes Phil