变更
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
def test():
|
||||
print("我是模块1")
|
||||
@@ -0,0 +1,2 @@
|
||||
def test():
|
||||
print("我是模块2")
|
||||
@@ -0,0 +1,12 @@
|
||||
def test(a, b):
|
||||
print(a + b)
|
||||
|
||||
|
||||
def test1(a, b):
|
||||
print(a - b)
|
||||
|
||||
|
||||
__all__ = ["test1"]# 只作用于*,可以手动单独导入函数
|
||||
|
||||
if __name__ == '__main__':
|
||||
test(1, 2)
|
||||
@@ -0,0 +1,2 @@
|
||||
def test(a, b):
|
||||
print(a - b)
|
||||
@@ -0,0 +1,36 @@
|
||||
# # 模块导入
|
||||
# import time
|
||||
# time.sleep(5)
|
||||
# print("你好")
|
||||
|
||||
# from time import sleep
|
||||
# sleep(2)
|
||||
# print(2)
|
||||
|
||||
# 导入自定义模块
|
||||
# import my_test as t
|
||||
# .test(2,4)
|
||||
# # 导入不同模块同名的功能
|
||||
# from my_test import test
|
||||
# from my_test1 import test
|
||||
#
|
||||
# test(2,5)# 下面的会将上面的覆盖掉
|
||||
|
||||
# __main__变量
|
||||
# import my_test as t
|
||||
# 调用的模块本身调用了函数,则调用时候会输出结果
|
||||
|
||||
# # __all__ 变量
|
||||
# from my_test import *
|
||||
#
|
||||
# test(1, 2)
|
||||
# test1(3, 8) # 未定义时,可以使用任意函数
|
||||
# # all定义时,只能导入定义的函数,但只作用于*,可以手动单独导入函数
|
||||
|
||||
# python的包
|
||||
import my_package.my_test1
|
||||
my_package.my_test1.test()
|
||||
from my_package.my_test2 import test
|
||||
test()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user