Python Instance Variables

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • 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.

Komentáře • 26

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

    John Philips Jones, You are a great teacher

  • @quazichimp
    @quazichimp Před 8 lety +10

    Wonderful...simple and clear, with just enough repetition to help it sink in.
    thanks again.

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

    Your videos are really great. Thanks for doing these.

  • @SN-je5ej
    @SN-je5ej Před rokem +1

    Thanks!

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

    Thx !!!!!!!!!!!

  • @eldarmammadov7872
    @eldarmammadov7872 Před rokem

    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)

    • @johnphilipjones
      @johnphilipjones  Před rokem +1

      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

  • @husseinshuriye6380
    @husseinshuriye6380 Před 7 lety +1

    Thanks, This helped me a lot!

  • @nasrullahturke4480
    @nasrullahturke4480 Před 5 lety

    >>> 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

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

      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

    • @nasrullahturke4480
      @nasrullahturke4480 Před 5 lety

      @@johnphilipjones Thanks John❤. I have watched that video on getter and setter after I had sent you my queries. Thank you so much.

  • @Lennardish
    @Lennardish Před 3 lety

    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 :)

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

      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

  • @leanneglenn3351
    @leanneglenn3351 Před 2 lety

    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?

    • @johnphilipjones
      @johnphilipjones  Před 2 lety

      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

    • @leanneglenn3351
      @leanneglenn3351 Před 2 lety

      @@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

  • @armingal2697
    @armingal2697 Před 5 lety

    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

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      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

  • @andrejoseph3630
    @andrejoseph3630 Před 8 lety

    But what is the difference with making an object and an instance

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

      An object is an instance of a class so there is no difference.
      Regards
      Phil

    • @andrejoseph3630
      @andrejoseph3630 Před 8 lety

      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.

    • @andrejoseph3630
      @andrejoseph3630 Před 8 lety

      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.

    • @johnphilipjones
      @johnphilipjones  Před 8 lety

      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

    • @andrejoseph3630
      @andrejoseph3630 Před 8 lety +1

      wow thank you but i was just looking over and I understand now thank you very much.

  • @KrishnaManohar8021
    @KrishnaManohar8021 Před 4 lety

    Object vs instance ???

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

      An instance of a class is also referred to as an object.
      Best wishes Phil