INFO1110 Lecture 9: 8B – Modules and methods

72 views2 pages

Document Summary

A module is a single file that contains related definitions, functions, and code: aim is to aid code organisation, modularity, breaks up code into developer-defined categories. In python, a module is a . py file containing source code. In python, import is a keyword that will open another file then inserts and executes all the code. All code is executed once when import is used for a module. Python keeps module contents out of current scope. Current scope is all the symbols visible to the current execution environment. Imported code is stored in an object, containing functions and related data. Module functions are variables from an object that can be accessed using dot notation: import numberoperations x = 2 print( numberoperations. get_square(x) ) print( numberoperations. get_min(29, 5) ) Can assign the import object to another variable name: import numberoperations as numops. Chained imports e. g. module a imports module b, which imports module c. # go straight to the source from moduleb import modulec.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents