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