00:0.14 Well let's take PyCharm's. Debugger for a spin.
00:3.14 And I've got an interesting little program here that we can play with because it has
00:6.93 some pretty unique flow and we'll be able to use the step over step into step
00:11.79 out of actually see some interesting things about how python works.
00:16.54 You might be familiar with the Fibonacci numbers there,
00:19.4 these numbers and then the next number is generated by taking the previous two and adding
00:23.95 them. So one plus two is 3 plus three is 5 plus three is 8
00:27.25 13. Anyone on and on or infinity.
00:32.54 I've got this program and we've got our other file here that's going to generate this
00:37.69 Fibonacci sequence. I've got this other math tricks thing that will given a sequence,
00:45.37 generate a subsequent of it for just the odd numbers.
00:50.14 So if we give it 112358,
00:52.79 it's gonna give us 1135 etc.
00:56.14 What's interesting about this is this is an infinite sequence and that is modeled here in
01:0.74 python were actually generating an infinite sequence.
01:3.05 And when we feed this one an infinite sequence,
01:5.8 the results is itself an infinite sequence,
01:8.53 assuming it has infinitely many odd numbers I suppose.
01:12.24 So what we're gonna do is we're going to explore how that flows know it might
01:16.39 sound tricky to generate an infinite series but in fact with the yield keyword it's ridiculously
01:22.49 simple. We're here, we're generating the numbers starting with 10,
01:27.49 they want to do this add together here,
01:29.84 we do the step to calculate them and then this yield is going to return the
01:33.86 value, we'll go work with it and then when we need more these co-routines
01:38.47 will allow us to jump back to where we left off basically this line and just
01:42.63 keep running one time and then another through that loop.
01:46.24 Same thing here we go through whatever series we find an odd one.
01:49.55 We give it up, it's on,
01:52.24 we're going to combine these two things in some interesting ways.
01:56.04 So first let's just run it and see what we get because this is an infinite
02:0.37 series. We can't just print them out.
02:3.24 Going to gather them up in this list actually then print it,
02:7.24 we have to say after some point,
02:9.24 I'm no longer interested in looking at the Fibonacci numbers so let's stop.
02:13.28 So let's run this real quick and there you have it.
02:17.15 1135 13 21. And then boom,
02:20.57 this stuff takes off super quick.
02:22.22 It's really interesting how big these get how quickly,
02:25.54 So isn't that cool? We generated this infinite sequence and then we filtered it down
02:30.54 and then we stopped. So let's go and actually set a breakpoint here and just
02:36.17 see what's going on. So we already have a run configuration so I can click
02:39.22 this, I could sort of skip it,
02:41.11 I guess by going debug here,
02:42.95 but just press this here we are in our definition of defining data,
02:48.6 we've done our import but that's about it.
02:51.14 We could step into we don't want to more likely to step into my code is
02:56.27 what we want. But I'm just going to step over for now.
02:59.01 We're just gonna look at this particular file the first time through first of all notice
03:3.31 right over here, there's this really cool grey thing at the end that wasn't there
03:8.37 before. And look at this,
03:10.68 this is the value of this list.
03:12.78 It's not very interesting yet it's empty but you can even see that we can interact
03:16.42 with it kind of like a hyperlink drop down thing.
03:19.2 Incredible. Now these are going to return what are called generators if you hover over
03:24.17 it, PyCharm even knows this is a generator didn't show us to us there
03:28.77 but if we weren't in the debugger it would show us that we step over
03:32.5 here is our generator named 'fibs'.
03:36.24 And then this one is going to be a generator named fib so look how quick
03:39.9 we generated to infinite series. That's because they're lazily evaluated.
03:44.52 Find some way to keep going.
03:45.99 We've got our variable O and are odd fibs and we're going to start to go
03:49.2 over them. Let's keep going.
03:51.01 Step along notice here's our one are always one when append.
03:55.94 Watch what happens online for appear around data.
03:59.94 Oh yeah, so it changed and because it changed,
04:4.04 it changes in this little overlay mode to orange,
04:7.52 that means had a value and now it's got a new value.
04:10.03 So that's really cool and you can see down here we can even expand out the
04:13.7 list and see it has one item.
04:15.4 Let's keep going. But one again now we should have our data has more,
04:20.96 see the index where it changes Now we have our three,
04:24.64 remember the Fibonacci sequence is 1123 but we filtered out the two with our generator for
04:30.84 the odd numbers. I keep going and just see it stepping along here.
04:37.04 Super cool. Now what if we said I'd like to see at this point exactly
04:41.18 what would happen if O was 9000?
04:44.44 So no problem. We can come down here,
04:48.14 we can click set value Or we could add as an in line.
04:52.06 Watch down here but I'm gonna just set the value.
04:53.91 What do you want to be said?
04:55.45 9000. Remember this is a situation that basically because of this function couldn't exist but
05:1.63 I want to figure out what happens if it's the case.
05:4.44 So now we've got these numbers and what should happen is we're going to break out
05:8.26 of this. Right? So we step done,
05:11.21 I printed out gone back over here are console there,
05:16.2 that's not the same output as before because we played with the debugger and we
05:19.59 changed it. How cool is that?
05:22.04 I cannot tell you how much it delights me to see the variables over laid and
05:26.45 code. Let's just go down here and say I want to run,
05:29.74 put a breakpoint first Run down here,
05:33.14 then I want to just go straight to this location bam.
05:35.85 Run to cursor and we've got there for the first time.
05:40.14 Notice all the variables here, but I cannot tell you how delightful it is to
05:43.21 be able to see these without,
05:44.73 you know, fiddling with this stuff down here or some other window,
05:47.97 You just see it right there and you can even interact with it as we've seen
05:51.48 So super, super cool.
05:54.31 Let's do another thing. Let's try to understand the flow.
05:58.14 These restartable co-routines,
06:0.21 they are mind bending if you have not played with them before.
06:3.05 So let's go back over here,
06:5.31 start to debugger. I'm gonna step into my code.
06:10.54 I just called that function and it didn't go into it.
06:14.12 That is weird. I'm gonna step into this one also didn't go into it.
06:18.09 Okay, confusing. A normal function it would step into,
06:21.26 but with the generators, what we do is we create these lazily evaluated sequences.
06:25.83 It's not until we first begin to interact with them,
06:28.46 like loop over them or try to get to some of them or something like that
06:31.71 but we actually execute them.
06:33.83 So here, vice type step into were in our odd series and then if I
06:39.83 type step into that, it's going to pull on the series.
06:42.19 The series is actually the Fibonacci generator.
06:44.81 You can see right there again.
06:46.32 Fantastically. Just over laid. All right.
06:49.25 Step, we're at the beginning,
06:51.37 this is the first time we call this function.
06:53.08 So we're going to step compute this now.
06:55.57 That's one and one. We're going to yield that.
06:57.39 It's going to come back for the value here.
06:59.49 So hold on for that. Oh,
07:1.33 there we are. And as one now,
07:2.81 we're going to yield that back over here.
07:5.98 This looks good when I put it on the list.
07:7.41 Now, if I step back into normal functions,
07:10.67 would go back to the beginning but not co routines and generators remember in is already
07:16.39 one going to step in again,
07:18.12 look where it went to, what's going to happen to current?
07:21.54  not 2, there's our to actually the next one will be too.
07:25.29 So this is one going to append it.
07:27.76 Step in again, this one is to we're not going to yield it,
07:32.09 so we're gonna loop inside. Go back here,
07:34.44 that'll be three and so on.
07:37.44 Hopefully that gives you a sense of what these generators are doing.
07:40.57 Their flow through code is very different than standard code.
07:44.48 But look how easy it was for us to see that just using step into my
07:48.88 code, basically. Really, really need to be able to do this with the
07:52.29 debuggers. And again, when we were in here we could see that the
07:55.64 series that was passed. Is this Fibonacci generator. Super cool.
