Python Guide Pack Learning Summary

Source: Internet
Author: User

Python beginner, for the guide package tangled a lot of time, summed up sharing, continuous progress ~

Two ways to guide the Python package:

1.1 from Package. Module Import method name, directly using method name () when invoked

1.2 from package. Module Import class name, which is invoked directly using the class name (). Method name (), that is, the method is called directly through the object

2.1 Import package. The module name is called when the absolute path is added , package. Module. Method Name ()

2.2 Import package. The module name is called when the absolute path is added, the package. Module. Class name (). Method Name ()

There are function1 function2 methods in the test, Class_1 and class_2 are class definitions, and the methods in Function1 and function2 are called separately in the following:

#import导包
Import test.function_2
Import Test.class_1
Def func_1 ():
Print ("Function 1")

Test.function_2.func_2 ()
    Test.class_1.test_class_1 (). Class_func_1 ()

#from  Import Guide Package
From test.function_2 import func_2
From Test.class_1 import class_func_1
Def func_1 ():
Print ("Function 1")

Func_2 ()
   Test_class_1 (). Class_func_1 ()
If you want to call methods between classes, you can also inherit
From test.class_2 import test_class_2  #导包
Class Test_class_1 (test_class_2): #继承
def class_func_1 (self):
Print ("Function of Class 1")
Test_class_2 (). class_func_2 () #对象. Method

Python Guide Pack Learning Summary

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.