Pythons id() function

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • Looks at Pythons id() function and uses it to show the relationship between a variable value and the variables ID.

Komentáře • 18

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

    a great video thank you.

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

    amazing!

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

    perfect!

  • @aniliskcon
    @aniliskcon Před 3 lety

    Your videos are amazing for beginners !! May I request videos on Exception Handling (try & except),(try, finally), ("with" construct, Context Manager). Thanks very much !!

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

      I will put your request in the pipeline and cover this topic.
      Best wishes Phil

    • @aniliskcon
      @aniliskcon Před 3 lety

      @@johnphilipjones thanks very much

  • @stanleyadeka
    @stanleyadeka Před 5 lety

    sir, will the id of say 7 always be the same regardless of the time it was assigned to a variable, lets say on a different project and time?? or even on a different computer, or is that particular id assigned to seven when it is created and copied to another variable with the same value?? are ids, always predefined to certain values or are they created at random, the question has been on my mind for a while, cause im thinking, if ids are predefined how does python assigned ids to strings place-held by variables , oh and thanks for your tutorials ive seen a whole bunch of them on different topics and im planning on finishing them all... from Nigeria

    • @johnphilipjones
      @johnphilipjones  Před 5 lety

      Everytime the program executes the id is allocated to the instance of the object. So the id can be different for every execution of the program. Once the program finishes executing all variables are effectively cleared from the memory by the operating system. The next time the program executes the operating system is highly likely to allocate it a different memory area in which to execute. This will result in a different id being allocated by Python.

  • @borisrunakov1662
    @borisrunakov1662 Před 9 lety +1

    Another great video !
    One question though : How would you illustrate the way the cpu implements your example ( a= 7 ) by means of address registers and data registers via adress / data bus ?
    Thank you !

    • @johnphilipjones
      @johnphilipjones  Před 9 lety

      boris runakov Hello Boris, Thank you for your generous comment. Have a look at the four videos I have done on machine code and the fetch decode execute cycle. The links to these video can be found on one of my websites at the following link:
      www.johnphilipjones.com/machine-code.html
      Or you can access the playlist on CZcams at:
      czcams.com/play/PL6lxxT7IdTxGXX6D6j-zjzcgoOD8WYMS2.html
      Hopefully these will help if not contact me again I I will forward another answer.
      Best wishes
      Phil

    • @borisrunakov1662
      @borisrunakov1662 Před 9 lety +1

      Great thank you very much!

  • @MaxGoddur
    @MaxGoddur Před 7 lety

    Shared your video links with some friends on KNow How

  • @MaxGoddur
    @MaxGoddur Před 7 lety

    Can this be thought of as:
    'a' is the memory address or id and 7 is the value at he memory address or value.

    • @johnphilipjones
      @johnphilipjones  Před 7 lety

      I recommend that you regard a Python variable as an object that has a value with the object having the id.

    • @MaxGoddur
      @MaxGoddur Před 7 lety

      Roger that.

  • @zahidullah1707
    @zahidullah1707 Před 7 lety

    means the variables id() will be the same if the value of the variables is same. Isn't it sir????

  • @asmartbajan
    @asmartbajan Před 9 lety +1

    9:16 Interestingly enough, if *3 + 4* were to be assigned to *b*, its ID would still be the same as that of *a* because *3 + 4 = 7*.
    Fascinating stuff!

    • @johnphilipjones
      @johnphilipjones  Před 9 lety

      Hello Wayne,
      Yes they would have the same id.
      Best wishes
      Phil