Python for Absolute Beginners Transcripts
Chapter: The big ideas of software development
Lecture: Source code vs. byte code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Here's our little check access functionality function that we had talked about previously. And it is five lines of code here, if you ignore
0:09 the blank lines in the comment which you can totally do that. What would it look like if we were to try to visualize this in bytecode?
0:16 Now, the actually bytecode that Python uses is binary data. It's like trying to print out a picture or a Word document or a ZIP file
0:26 without decompressing it, using a tool that understands it it just is a bunch of ones and zeroes and it's kind of
0:31 meaningless if you try to look at it directly. But there's a way that we can say Python, show me the text representation of this
0:39 as you understand it, so it basically becomes legible to us. And if we do that, if we take this over we get something that looks a whole lot more
0:47 like a bunch of little tiny steps no so much exactly like what we wrote here. I just want to point out you do not need to remember this.
0:54 You definitely do not need to be able to tell us what each one of these pieces does or to create it yourself. This is just so you have a sense of
1:02 when I say, Python, run that, what actually happens. What happens is it goes through that compilation parsing step that turns it from that source code
1:10 through this tree structure, into this bytecode. And then it saves those to a file and when you run it, it just runs 'em from top to bottom
1:17 following the jumps as it might need to. So it says things like load the age load the constant number 14
1:23 and then compare the two things that were loaded and if it's false, go to 20. So 20 is return true. Down at the bottom, you can see
1:31 I've made that orange for you. So what you write and what the program actually does step by step is not exactly the same.
1:38 There's a lower-level bit that's happening and, of course, this is still high-level. This is not actually machine instruction
1:46 zeroes and ones, assembly language-type of thing. This is still higher than what is happening on the CPU
1:51 but this is really how Python understands what you're doing and it can basically know the machine instructions to do each one of those steps
1:59 to load paths, load confs, compare off and so on. So when you run your code it first gets turned into this stuff and this is what actually runs.
2:06 Again, you don't have to be able to work with or create this bytecode, just so you have this working concept of what's actually happening
2:13 when you run your program. Well, it turns into bytecode and it processes them one at a time, from top to bottom
2:19 unless there's a jump or some kind of way to move around in there.


Talk Python's Mastodon Michael Kennedy's Mastodon