PLEASE SUBSCRIBE!!!
In the previous lesson ( • Python Programming: Lesson 60 - The _... ), we took a look at the _contains_ magic method, which enables us to define what it means to ask if an element is IN an instance of a class. We also brought up the iskeyword and type functions. In this lesson, we will review some of these object-oriented fundamentals (including some more OOP stuff from earlier), but we will also talk about running a module as a script.
Recall that type(x) shows us the data type of the item x
the iskeyword(s) function from the keyword module returns True if s is a Python keyword (shows up in orange), False otherwise
The _call_ magic method of a class C allows us to create an instance E of C as though it were a function E( ) that we could call, potentially with inputs.
The _contains_ magic method of a class C allows us to define X in E for some item X and instance E of C. It is instructed to return True or False.
If we write
if _name_ == "__main__":
then anything in that boolean will executed first. It allows us to treat our module as though it were a script that we could immediately call.
6:52 Review of callable and contains magic methods
9:43 Review of keyword function from the iskeyword module
11:22 Review of the type function provided by Python
13:10 NEW: Running a module as a script with if _name_ == "__main__":
In the next lesson, we'll talk about the exec function and iterators. Neat stuff, don't hesitate: • Python Programming: Lesson 62 - Itera...
Thanks for watching, and PLEASE SUBSCRIBE!!!
Watch video Python Programming: Lesson 61 - Running a Module as a Script online, duration hours minute second in high quality that is uploaded to the channel youmils03 05 November 2021. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 30 times and liked it 0 visitors.