Rock Solid Python with Python Typing Transcripts
Chapter: Static vs. Dynamic Languages
Lecture: Using the Untyped Motorcycle

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We have our motorcycle class up here, but let's go ahead and use it.
0:05 Let's come down here and say we're going to create a function called create bikes or motorcycles, like so.
0:12 And it's going to have bikes like this, and then somewhere it'll return the bikes. And we're going to leverage our create adventure thing.
0:21 And we'll create a bunch of different kinds. We'll create a Himalayan 410, a Tenere 700, a KTM 790, and a Norden 901.
0:29 All of these are different types of adventure motorcycles. All right, so we've got them, and then let's go ahead and use them down here.
0:37 We'll use the standard dunder, if dunder name is dunder main, to say we're running this code,
0:45 so let's actually do some action instead of just import it. And I have a shortcut here, a live template in PyCharm that I created called name,
0:54 that if I hit tab, it writes this, because who wants to type that all the time. So we'll just say bikes equals create bikes
1:02 and then for B and bikes, just print out B. Great, now if we wanna run this in PyCharm, you can see it will run the current file,
1:10 but kinda wanna force it to run just this one, even if I have the C# file open. So let's go and say run, right click on this and say run.
1:19 And notice you can see the command is running our virtual environment Python. again, over here, that file, as you would expect,
1:30 here's some bikes, and you can see it did exactly as we would like, this is the stir method for the class, we're just printing out the bike there.
1:40 You can see as we start to use it, yes, there's some inference about where this might actually
1:48 be useful, where this, what kind of information is required, like, okay, that looks like it really is an integer, not a string or anything like that.
1:58 So we're getting more information about how the types fit together, but it's just what we gleam from the code as we go through it.
2:07 One final thing is I called this bikes and that bikes and it's not happy saying. This thing is shadowing this global one.
2:14 So let's just rename that real quick to motor cycles. Check it still runs. Awesome.


Talk Python's Mastodon Michael Kennedy's Mastodon