Copying Python Object References

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • A 'schematic animation model' that looks at how an object reference can be copied to another object reference.

Komentáře • 21

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

    wow, this is the fourth module in this playlist and I still can't believe I came across this course by accident. you are a great teacher sir😍😍

    • @johnphilipjones
      @johnphilipjones  Před 2 lety

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

  • @deepv446
    @deepv446 Před 4 lety +9

    No one explained python this way ♥️

  • @user-bl4lu4kv3b
    @user-bl4lu4kv3b Před 3 lety +2

    Excellent explanation, please continue this way, and thank you, sir.

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

    Love your videos and the way you teach - old video, still relevent.

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

      It is good to know that the videos are helping. Thank you for the positive feedback.
      Best wishes
      Phil

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

    I am enjoying your videos, very clear. Thank you.

    • @johnphilipjones
      @johnphilipjones  Před 2 lety

      Glad you like them
      Best wishes
      Phil
      (John Philip Jones)

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

    thank you what happens in case of mutable objects like list and dict data structures

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

    Sir , hope you doing great !!!
    I have a question
    Like if
    a = 10
    b = 10
    then, are they creating different object or a and b both are refrencing to same object

  • @mikijasar2594
    @mikijasar2594 Před 4 lety

    Dear Mr. Jhonson, can you please explain how shallow and deep copying fits into your python object model ? Thanks in advance

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

      I have a video in the pipeline but in the meantime I can give a text explanation. Consider a list of integers and let's say they are holding the integers 11, 27 and 32. Each element of the list has an object reference to one of the integers. Let the first element have the object reference to the integer that has the value 11. The second element has the object reference to the integer object that has the value 27. The third element has the object reference to the integer object that has the value of 32.
      A shallow copy for the example above would copy the object references from the three elements of the list to the new list that would also have three elements. For this new list the first element will be pointing to the integer that has the value of 11. So the first element of both lists will be pointing to the same integer object that has the value of 11. Continuing with this the second element of both lists will also be pointing to the same integer object the one that has the value of 27. The third element of both lists would have the object reference to the integer has the value of 33.
      So before the shallow copy there would have been 4 objects. An object for the list has 3 elements and the three integer objects.
      After the shallow copy there will be 5 objects. The same objects as outlined in the last paragraph plus the new list object. Both lists point to the same integer objects.
      The list objects share the original three integer objects. This means that the integer objects are not copied I.e. you do not get three more integer objects created.
      A deep copy would also arrange for the new list to have object references to copies of the original integers. So the new list will have different object references stored within it because it will be pointing to three new integer objects.
      It takes more processing time to make deep copies. Think about the amount of copying needed if you had a list of 1000 integers objects.
      Best wishes Phil

  • @mikijasar2594
    @mikijasar2594 Před 5 lety

    I have a question
    Since at the end of this video we see that we have two variables completely different variable with different object reference en objects how come they are in the same Execution space
    although they have different Id ? Wouldn't it be logical to be made new Execution space for a brand new variable in this case first_number. Thank you in advance

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      The execution space is the space for the entire runtime of the program. Therefore all program variables exist in the execution space together with the program instructions that manipulate the data in the variables.
      Think of the execution space as something that contains communicating instances of classes I.e. communicating objects. These objects communicate with each other requesting services from each other. That is a message is sent from one object to another and this causes a method to execute. The method contains the instructions that manipulate the data stored in the data attributes of the object.
      Best wishes
      Phil

    • @mikijasar2594
      @mikijasar2594 Před 5 lety

      @@johnphilipjones
      Thanks for your quick reply

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

      I thought when you were talking about execute space
      that you are talking about sectors in hard disk or RAM mamory but now i understand that you mean the total memory space of your computer

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

    Sir can you make videos of django...?

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

      Will put in the pipeline but it will be a while off as I will be working on tkinter for a few months.
      Best wishes
      Phil

  • @confidential303
    @confidential303 Před 8 lety

    What i am wandering, if you have a iterative process of calculating variables and put that in an array or table, there will be no endless space so the memory will have its constraints, do you as a programmer have to take that into consideration when writing memory intensive programs?

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

      +confidential303 Memory allocation is automatically taken care of by Python. However, they are always better ways to implement algorithms that make programs more efficient.
      Regards
      Phil