What is the Python Interpreter? (How does Python Work?)

Поділитися
Вставка
  • Опубліковано 24 гру 2024
  • What is the Python interpreter and how does Python work internally?
    In this video, I talk about how the Python interpreter works and how it runs your Python source code. Essentially, the Python interpreter is comprised of two subsystems:
    1- A compiler: this compiles your source code into an intermediate code called the 'byte code'
    2- A Python virtual machine (PVM): this interprets and executes the byte code on your machine.
    A good understanding of the concepts discussed in this video is crucial if you want to master the Python programming language.
    Resources:
    📝 Python Cheatsheet: www.afternerd....
    🖥️ Computer Science guide: www.afternerd....
    🐍 Python roadmap guide: www.afternerd....
    Courses:
    📚 Python OOP: www.afternerd....
    Where you can find me:
    ℹ️ Website: www.afternerd....
    📸 Instagram: / the_kreamix
    🐦 Twitter: / afternerdtweets

КОМЕНТАРІ • 166

  • @sajalchuttani2519
    @sajalchuttani2519 Рік тому +28

    just devoted 4 hours today learning how the python interpreter works and this video just summarized it into a 15 min video . Nice explanation , love the way you just go about explaining the stuff on a digital white board instead of some fancy animation stuff (which ofc increases information quality) SUBSCRIBED

  • @ryezizzle
    @ryezizzle Рік тому +5

    dude, i spent all day trying to figure this stuff out, and you explained it so well. subscribed!!!!

  • @androsp9105
    @androsp9105 Рік тому +1

    Thank you for explaining this.

  • @quitchiboo
    @quitchiboo 10 місяців тому +1

    Late to the party, but pretty much instantly subscribed. Clear, to the point, minimalist yet highly effective visual aids.

  • @web-unlocked
    @web-unlocked 6 місяців тому +1

    This is the best python mechanism of action explanation I've seen on the internet

  • @gd2860
    @gd2860 7 місяців тому +1

    Im the type of person who has to learn it from a very high level first then, the rest should fall into place. This fills a lot of gaps that ive had in getting started with python. Im new to this but again, I need to see the big picture first. Im an old network guy who mastered networking years ago. Been shying away from network automation but its what's here now and literally in my face at the workplace. Excellent explanation. Well done!

  • @umarbshehu7647
    @umarbshehu7647 Рік тому +1

    Wow! You just saved a life here. Thanks a bunch.
    Is there a continuation of this video?? You stopped halfway.

  • @CadPixel-why-not2455
    @CadPixel-why-not2455 Місяць тому

    great explanation , everyone says python is an interpreted language line by line but this vid says it all , thanks

  • @karimamri4831
    @karimamri4831 Місяць тому

    You brought honor to our name in explaining the concepts well, good job! and thank you!

  • @Bojan456
    @Bojan456 Рік тому +3

    Amazing video. I love the added details from your old job and how it helps you to understand the new one. Thanks for sharing.

  • @aryandugar9810
    @aryandugar9810 3 роки тому +4

    this was awesome. i have not seen content about such python concepts explained so well!

  • @averystehr
    @averystehr 3 роки тому +22

    Thank you so much! Well said! I've been trying to find this exact information.

  • @PhamLinh-u3z
    @PhamLinh-u3z 9 місяців тому

    Your way of explaining things is really clear and easy to understand! Thank you so much

  • @steveq1881
    @steveq1881 3 роки тому +4

    I've been searching for this info everywhere! Thank you so much for going into the details of how it really works.

  • @danbromberg
    @danbromberg Рік тому

    Excellent under-the-hood- description of what's going on!

  • @ahmed51988
    @ahmed51988 2 роки тому

    A very nice in-depth yet simple explanation

  • @MAYANKKUMAR-vm3gy
    @MAYANKKUMAR-vm3gy Рік тому

    Awesome extremely clear explanation, quick fix of basic python confusion..

  • @linguaphile24
    @linguaphile24 7 місяців тому

    This is so clear and informative i like to know whats going on to understand later how things work even if i wont go deep to these codes. Thank you for this

  • @jetbob309
    @jetbob309 6 місяців тому

    I like your style of delivery! Id definitely buy a course from you! Thanks for the video

  • @MagicM2024
    @MagicM2024 3 місяці тому

    Nice done. Thank you for this great and easy to catch tutorial

  • @brady1045
    @brady1045 3 роки тому +7

    Well explained and super helpful, thank you!!

  • @uchihalayan3435
    @uchihalayan3435 2 роки тому

    this is the best explanation for the interpreter thank you so much

  • @lucascerveracom
    @lucascerveracom 8 місяців тому

    Great explanation! Thanks for sharing your knowledge in such an easy to understand way

  • @sowmyaganiga4155
    @sowmyaganiga4155 9 місяців тому

    Thanks for the information this is what needed to start with anything in IT , Please make more and more videos on basics

  • @Fb-uv4jj
    @Fb-uv4jj 4 роки тому

    came here from your website. i think that you explain simple because you know subjects well. useful for me. high quality content.

  • @milton7285
    @milton7285 4 роки тому +2

    Thanks for a simple video. Keep it simple!

  • @SUPERHEAVYBOOSTER
    @SUPERHEAVYBOOSTER 2 роки тому

    This was awesome. Thank you so much. It's so rare to find channels that really dig in deep!

  • @AdrianCortes-b7f
    @AdrianCortes-b7f 2 місяці тому

    I love that you said that ones and zeroes are just voltages on transistor

  • @estebangomez1823
    @estebangomez1823 Рік тому

    This nailed it!!! Happy to found this channel!

  • @ColonelHathi
    @ColonelHathi Рік тому

    This the best video explaining how an interpreter works. Thank you for giving details and examples, not hand waving magic! 😊

  • @WaldoTheWombat
    @WaldoTheWombat 7 місяців тому

    Thank you Karim, excellent video! Why do interpreters convert source code to machine code one row at a time unlike compliers that convert the entire file all at once and what is the consequence of this difference?

  • @thedoremaq
    @thedoremaq Рік тому

    Thanks!

  • @Aksinia1599
    @Aksinia1599 Рік тому +1

    This is so enlightening! I have been looking for such explanation. Thank you very much for the video.

  • @ublack8749
    @ublack8749 Рік тому

    thank you very much dear....

  • @merrymouse2008
    @merrymouse2008 10 місяців тому

    Wonderful video! You explain it so nicely and it is easy and interesting to follow. thank you so much for making it!

  • @navnitkumar138
    @navnitkumar138 10 місяців тому

    Nice Explanation. Very impressive tutorial for me. Now I learnt How Interpreter works. Thanks a lot..!

  • @UnleashedEntomber
    @UnleashedEntomber Рік тому

    Well, it's the best explanation on the internet, what can I say. Great job!

  • @Nidza11q
    @Nidza11q 3 роки тому +5

    Great stuff,so easy to follow and understand.It helps us,beginners,a lot!!

  • @hemalakshmi1187
    @hemalakshmi1187 Рік тому

    your teaching was amazing and thankyou so much

  • @soulelemanator97
    @soulelemanator97 2 роки тому

    This was so helpful and well said

  • @RaviRaj-je3rh
    @RaviRaj-je3rh 3 роки тому +1

    Karim bro😎...Truely useful content & logically presented .... 🐅

    • @Afternerd
      @Afternerd  3 роки тому +1

      Ravi! Thanks my man!

  • @HemanthKumardigital
    @HemanthKumardigital Рік тому

    Thanks bro , for clear explination its really helps

  • @mosheglobus1124
    @mosheglobus1124 3 роки тому +1

    Thank you. High-quality content!

  • @MohyDev
    @MohyDev Рік тому

    Hey Karim, that was really great thanks!

  • @ben_jammin242
    @ben_jammin242 Рік тому +1

    I was hoping this video was going to explain the actual parsing of the python code into the execution model, defines, declares/variables, function calls. Lovely video though. Thanks for the explanation. It was extremely thorough and concise - you definitely seem to take the time to really understand things. Would love to see more content by you :). Great personality too. ❤
    Edit: syntax tree I think is the terminology I was missing above

  • @prateeksharma962
    @prateeksharma962 2 роки тому

    Great Video. Seen others, but this is the best explanation that I have come across. Thank you, you have strengthen my understanding.

  • @ItzRaiyan
    @ItzRaiyan 3 роки тому

    Brilliant Video! This was a very informative and detailed video

  • @jeeveshvanga2598
    @jeeveshvanga2598 2 роки тому

    cool and clear explanation 🎉

  • @rajarsiroy6362
    @rajarsiroy6362 Рік тому

    Great explanation, thanks

  • @barjammar
    @barjammar 2 роки тому

    Thanks. I agree with you that understanding stuff is easier than just learning and remembering. I'm also looking for a lesson on what all the windows are in PyCharm. How do I get rid of them or use them. Also, point a particular window at the file in use rather than the file I was using yesterday!

  • @gopesh97
    @gopesh97 Рік тому

    Amazing!!
    Thank you so much for posting this.

  • @blandon93
    @blandon93 Рік тому

    .pyc is some kind of assembler-like program. instruction 1 is write to a memory adress. q is how does it know where to write, I guess python takes some portion of ram when you run the interface, or OS give the adresses.

  • @yusupovjasur
    @yusupovjasur 2 роки тому

    Great in-depth tutorial, thank you!

  • @YesuSira
    @YesuSira 2 роки тому +1

    Thank you, this was basic and explained in easy-to-digest bites.

  • @utkarshujwal3286
    @utkarshujwal3286 Рік тому

    Thank you so much. It clarified a lot of my doubts.

  • @johnkunz7798
    @johnkunz7798 Рік тому

    This is such an awesome explanation. I've watched and read stuff on the GIL and how it regulates threads. Please explain this and how this somehow works optimally for IO operations.

  • @gianireyes405
    @gianireyes405 4 роки тому +2

    Man, this is pure gold. I've been many time asking myself and looking for this information, and finally I got a good explanation. Thanks, really.
    Aaaaaand I have a question if u don't mind: When you talk about the "memory" , you mean the memory unit in the processor, or something else ?

    • @Afternerd
      @Afternerd  4 роки тому +3

      I am happy to know that someone “cares” about this level of detail :). Thanks for your kind words. And yes, you are right, I am talking about the RAM that comes with your desktop/laptop. It is not really “in” the processor but it is connected to the processor. A processor has a component called a memory management unit (MMU) but this is not what I am talking about. I am talking about the actual RAM.

  • @hanan_almulla
    @hanan_almulla Рік тому

    finally a great explanation!! thanks a lot :)

  • @subhashgn1775
    @subhashgn1775 2 роки тому

    Very well explained....👌👌
    Thank you..🤝

  • @aryamick
    @aryamick 2 роки тому

    Thanks a lot, bro!! That was indeed both insightful and easy to understand.

  • @zui0per342
    @zui0per342 3 роки тому +1

    Started learning python today, i wonder why there are not that many people here

  • @zakriazaheen7616
    @zakriazaheen7616 4 роки тому

    I recommend sir lectures for very beginners so much friendly and easy .

  • @LC-sx2ht
    @LC-sx2ht 2 роки тому

    Great explanation, thank you!

  • @jordinp2140
    @jordinp2140 3 роки тому

    I needed this, Thanks! Really well done.

  • @azertyman776
    @azertyman776 3 роки тому

    Nice video ! It helped me a lot, keep going !

  • @davidkuda7074
    @davidkuda7074 3 роки тому +1

    that was very informative, thank you so much for doing this!

  • @reccon_game
    @reccon_game 2 роки тому

    Thank s this is very easy to understand

  • @promechafox8083
    @promechafox8083 2 роки тому

    What an Amazing video. Very Easy to understand : )

  • @qusirramzan3497
    @qusirramzan3497 2 роки тому

    Hi, dear can you please explain that why we get error while run this instruction 2**2 in Python Terminal (VS Code) [Error: You must provide a value expression following the '*' operator]

  • @lxzhang4911
    @lxzhang4911 4 роки тому +4

    Hi Sir, thanks a lot for the video. It's really very helpful. Still I have a doubt: if in the source code there are more than one statements e.g. 1). a=3, b=5; 2). c=a+b; 3). print c; Will all the statements be compiled into the byte code at one time and then dealed with PVM? Or the 1st statement will be compiled and handled by PVM, then the 2nd compiled and handled by PVM, then the 3rd compiled and handled by PVM?

    • @Afternerd
      @Afternerd  4 роки тому +6

      Great question! First off, this is an implementation detail. There are various Python implementations. In CPython (the canonical Python implementation), all source code statements will be compiled into byte code first, and then the PVM will fetch and execute the byte code one instruction at a time. There are some implementations however that use JIT for example which is closer to the first case that you described.

    • @lxzhang4911
      @lxzhang4911 4 роки тому +3

      @@Afternerd Yes I see in the wiki, there are several variations of interpreter. But I cannot understand them that clearly. Anyway thank you a lot for your video and your answer! It helps me a lot:)

  • @mo7sin711
    @mo7sin711 7 місяців тому

    I need help
    I'm studying the freecodecamp course, and when i type the following code for the conditional exercise
    x = 0
    y = 10
    if 0 == x:
    if y == 10:
    print('YES')
    the output in the VS code terminal is Syntax Error
    however when I run it in python itself or an online compiler, it runs successfully and prints YES
    I need help :(

  • @madhanrajmoorthy8843
    @madhanrajmoorthy8843 3 роки тому +3

    Hi Bro, It's amazing way you have explained. I was expecting in my mind to learn like this. Since, the understanding of hard part will be reduced when we learn using basics with super diagrams. Hats off bro. Thank you so much. :)

    • @Afternerd
      @Afternerd  3 роки тому +2

      Glad you found it useful! Thank you.

  • @personsname0
    @personsname0 3 роки тому

    Great explanation!

  • @Mike-og4wc
    @Mike-og4wc 2 роки тому

    Great video, thanks a lot!

  • @tehDIMND
    @tehDIMND 3 роки тому

    thx man, awesome explanation :)

  • @guilhemescudero9114
    @guilhemescudero9114 3 роки тому

    THANKS! Amazing work man!

  • @tatyanatarasova6480
    @tatyanatarasova6480 2 роки тому

    I'm a nerd! )) couldn't stop asking myself how it works. Thank you!

  • @mujelsh9347
    @mujelsh9347 4 роки тому

    Thank you brother. Great video Ya Mo3alem

  • @matheuscerozi6649
    @matheuscerozi6649 2 роки тому

    thank you, it helped me a lot

  • @awusacollins
    @awusacollins Рік тому

    Great explanation)

  • @yonahcitron226
    @yonahcitron226 2 роки тому

    Really Great info

  • @terrencemasuku8909
    @terrencemasuku8909 2 роки тому

    man that was so cool. keep it up

  • @ricomajestic
    @ricomajestic 3 роки тому

    Do you recommend any books that go under the hood of python even deeper? That also go into why the language was designed the way it was, how and why it works the way it does, why it’s better than other languages, why it’s not, etc.

  • @snippletrap
    @snippletrap 2 роки тому

    Why compile to VM byte code? Why not compile directly to machine code?

  • @fentazimohamedreadh5274
    @fentazimohamedreadh5274 2 роки тому

    Thank you for making this video. I managed to understand it clearly (though I have a decentbackground in computer science). But I'm sure even a beginner would understand modt of it.
    Make more of those thank you!

  • @Coolbassist
    @Coolbassist 3 роки тому

    Hey, great video! Im just wondering what terminal you are using? Looks great!

    • @Afternerd
      @Afternerd  3 роки тому

      Zsh with some custom configuration. Just google zsh and ohmyzsh

  • @renanaoki714
    @renanaoki714 Рік тому

    Now all make sense, thanks 👏👏👏👏👏👏👏

  • @avikjis27
    @avikjis27 3 роки тому

    Following the steps you mentioned, I didn't find the __pycache__(double underscored) folder created in my OSx machine. Any clue why? But if I use python 2 then it creates hello.pyc file in the same directory.

  • @amarpreetkaur4477
    @amarpreetkaur4477 2 роки тому

    Where I can apply for job if I have only knowledge of 3 levels?

  • @celestial2091
    @celestial2091 3 роки тому

    Amazing video!!

  • @sosobel5220
    @sosobel5220 3 роки тому

    Please, is it possible to compile into java bite code than run the code under jvm which mean output a 100% java code.

    • @herdenq
      @herdenq 2 роки тому

      It's certainly possible. You may need to write the compiler, though.

  • @emaniftikhar4632
    @emaniftikhar4632 3 роки тому

    So am I right that the memory stores programs and the CPU fetches those programs/instructions to execute them and hence produce an output ?
    Also why is python script mode and python shell are known as python interpreters?

  • @quicksilver5413
    @quicksilver5413 2 роки тому

    Hey thank you for this info. How is the processor involved in running the code? You mentioned in the video that the python virtual machine is responsible for executing the code. Does that mean the processor is not involved at all?

    • @quicksilver5413
      @quicksilver5413 2 роки тому

      Since in the diagram the pvm seems to be loaded just in memory

    • @jr.wick2339
      @jr.wick2339 Рік тому

      @@quicksilver5413 I have the same query.

  • @hisstoryinthemaking613
    @hisstoryinthemaking613 2 роки тому

    excellent work explaining this.. very practical 🙂👌🏽

  • @mayeganfriends6678
    @mayeganfriends6678 9 місяців тому

    I'm subscribing.....Gold information here

  • @che_kavo
    @che_kavo 3 роки тому +2

    Probably this is not a very good question :) I'm just wondering why the compiler in python transforms code into binary code, not in machine code directly?

    • @gentworm2377
      @gentworm2377 3 роки тому

      I believe it's for performance. It would also take too much effort for normal code to be converted straight to machine code. It also allows for more functionality and uses. An example of more functionality would be in Java, where you can serialize extra data into bytecode for things like saving data, etc. Finally, it won't make sense to translate code with errors straight into machine code, it needs to get changed to binary to analyze these errors (byte code and binary are the same thing).

  • @VinodMoorkoth
    @VinodMoorkoth 3 роки тому

    Great Video bro

  • @CanDoSo_org
    @CanDoSo_org Рік тому

    Hi, to be frank, this does not help me to understand different python path or environment. There are several python versions in my MacBook. But it always report errors when I use python in different IDE, like Rstudio, VsCode, or terminal. Very confusing when I run into such error warnings.

  • @kedarhargude643
    @kedarhargude643 3 роки тому

    Woww!! Wonderfully articulated bro. Pure gold. Have a question though...why did anyone decide to use compiler, then PVM for python? Can't they just do simply like how C language is processed by only a compiler??

    • @Afternerd
      @Afternerd  3 роки тому +1

      Great question :) much like Java, having an intermediate language (byte code) allows you to take this byte code and run it on any other machine. Another reason is, which is not usually spoken of, is that it is actually a lot easier to implement a virtual machine than to translate a source code into a machine language. The later requires tremendous knowledge of the underlying processor and its instructions, the former doesn’t.

    • @guilhemescudero9114
      @guilhemescudero9114 3 роки тому

      ​@@Afternerd If I understand well what you are saying : for a given python program in different platforms and machines, the byte code will be the same but the python interpreter is different in each machine : its output while reading the byte code will be proper to the hardware of the machine, isn't it?

    • @Afternerd
      @Afternerd  3 роки тому +1

      @@guilhemescudero9114 correct!

  • @web_hub
    @web_hub 2 роки тому

    Thank you, sir ☺️💛