# 模块 module
def my_sum(*args): # 求和函数
result = 0
for item in args:
result += item
return result
# print(my_sum(1, 2, 3, 4)) # 10
def my_max(*args): # 打印最大值标志----此处仅仅打印一点内容
print("最大值")
def my_min(*args):
print("最小值")
class People: # 定义一个类
def __index__(self, name, age):
self.name = name
self.age = age
MAX_NUM = 100 # 定义一个变量
Above functions or classes may also be used in other .py files, then I should be allowed above may be used by other files. This method is equivalent to the C language header file
What I add a .py file in the project, you will want to share functions into them
This can create a new package, named demo, drag the file to the demo above helloworld.py
Create a .py file on helloworld, the demo file and directory at the same level
In the following input test.py
from demo.helloworld import my_sum
print(my_sum(1, 2, 3, 4, 5)) # 15 可以使用helloworld.py中定义的求和函数