Toptube Video Search Engine



Title:if __name__ == '__main__' for Python beginners 📥
Duration:09:13
Viewed:6,665
Published:27-05-2024
Source:Youtube

# if __name__ == __main__: (this script can be imported OR run standalone) # Functions and classes in this module can be reused without the main block of code executing # Good practice (code is modular, helps readability, leaves no global variables, avoids unintended execution) Ex. library = Import library for functionality. When running library directly, display a help page. # ---------- script1.py ---------- # This file can run standalone or be imported def favorite_food(food): print(f"Your favorite food is {food}") def main(): print("This is script1") favorite_food("pizza") print("Goodbye!") if __name__ == '__main__': main() # ---------- script2.py ---------- # This file should run only standalone from script1 import * def favorite_drink(drink): print(f"Your favorite drink is {drink}") print("This is script2") favorite_food("sushi") favorite_drink("coffee") print('Goodbye!')



SHARE TO YOUR FRIENDS


Download Server 1


DOWNLOAD MP4

Download Server 2


DOWNLOAD MP4

Alternative Download :