Python programming skills 2. python programming skills

Source: Internet
Author: User

Python programming skills 2. python programming skills

Modularization-this is what our programmers dream of. modularization can avoid repeated manufacturing wheels.

At the same time

The module enables you to logically organize your Python code segments.

Assigning relevant code to a module makes your code easier to use and understand.

The module is also a Python object and has random name attributes for binding or reference.

Simply put, a module is a file that saves Python code. The module can define functions, classes, and variables. The module can also contain executable code.

 

Take the output as an example:

Encapsulate the printed data as a module. Each call to the module outputs the text starting with hello.

 

Module code:

Vim demoModule1.py

The content is as follows:

#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
# Definition module: begin:
Def sayHello (hello ):
Print "hello,", hello
Return ## end definition end


 

The functions of the module are as follows:

#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
# Functions defined in demoDE. py of the import module
Import demoModule1

# Call function in demoDEF. py
DemoModule1.sayHello ("haha ")
### This call method is the wrong sayHello ("++ 1234567 ++ ")

 

 

Run and output:

 

Error summary:

This is a forgotten addition:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.