Python:main function

Source: Internet
Author: User

What is a function?

A program can contain more than one module, the more complex the program, the more modules and functions involved, the module subdivision contains more than one class, the concept of class in any object-oriented language is very important, in the class is the main is the inclusion of functions, functional implementation of a function of the code body, the function of the code the most basic encapsulation.

So multiple functions form a class, multiple classes form a module, and multiple modules form a program.

Main function, one entry for the whole program

Such as:

def Add (num01, num02):

return num01 + num02

def Sub (num01,num02):

return num01-num02

def Mul (num01,num02):

return NUM01 * num02

def Div (num01,num02):

return num01/num02

Print (Add (100,200))

Print can be printed, without the main function can also be run, the code will be scanned from the beginning to end, found that the whole is a function, will not execute, wait for the call. In order to make the code more readable, you should set a code for the program, the entire code is the main function,

the entry of the program main function , The code starts here to execute

Such as:

def Add (num01, num02):

return num01 + num02

def Sub (num01,num02):

return num01-num02

def Mul (num01,num02):

return NUM01 * num02

def Div (num01,num02):

return num01/num02

# Getting Started with the program, Main function

if __name__ = = "__main__":

Print (Add (100,2 00))

Demo : There is a green triangle in front, which represents the code for the sweep codes, and the command executes from this function.

Call the previously written function

Such as:

Import into the function module

Class

def function

Such as:

Import demo01 call demo01 inside the program

Choose Demo02 at the time of execution

Python:main function

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.