- Cloud Native Python
- Manish Sethi
- 200字
- 2021-07-02 19:11:56
Modules
A module basically allows you to logically organize your programming code. It is similar to any other Python program. They are needed in scenarios where we need only a bit of code to be imported instead of the entire program. A module can be a combination of one or multiple functions classes, and many more. We will use a couple of inbuilt functions, which are a part of the Python library. Also, wherever needed, we will create our own modules.
The following example code showcases the structure of modules:
#myprogram.py ### EXAMPLE PYTHON MODULE
# Define some variables:
numberone = 1
age = 78
# define some functions
def printhello():
print "hello"
def timesfour(input):
print input * 4
# define a class
class house:
def __init__(self):
self.type = raw_input("What type of house? ")
self.height = raw_input("What height (in feet)? ")
self.price = raw_input("How much did it cost? ")
self.age = raw_input("How old is it (in years)? ")
def print_details(self):
print "This house is a/an " + self.height + " foot",
print self.type, "house, " + self.age, "years old and costing\
" + self.price + " dollars."
You can import the preceding module using the following command:
# import myprogram
推薦閱讀
- The Supervised Learning Workshop
- Expert C++
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)踐教程
- Spring Boot+Spring Cloud+Vue+Element項(xiàng)目實(shí)戰(zhàn):手把手教你開發(fā)權(quán)限管理系統(tǒng)
- The DevOps 2.4 Toolkit
- 你不知道的JavaScript(中卷)
- Mastering Predictive Analytics with Python
- bbPress Complete
- RabbitMQ Cookbook
- Programming with CodeIgniterMVC
- 小程序,巧應(yīng)用:微信小程序開發(fā)實(shí)戰(zhàn)(第2版)
- C# Multithreaded and Parallel Programming
- C++ Fundamentals
- Akka入門與實(shí)踐
- Node.js實(shí)戰(zhàn):分布式系統(tǒng)中的后端服務(wù)開發(fā)