#pip install 安装
#pip list 安装列表
#pip uninstall 卸载
#wint = Ctrl + ~
'''
C:\users\用户名\pip\pip.ini
没文件夹自己创建
'''
'''
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
'''
文件名称
Module.py
#创建对象
class Person:
#定义函数或方法def
#初始化
#返回值。None无返回值
def __init__(self,name:str,value:int = 2020) -> None:
#self代表类的对象
self.name = name
self.value = value
def GetMoney(self):
return self.value
class Mods:
def __init__(self) -> None:
self.name = 'NaNa'
self.value = 2048
#函数
class Function:
#无参数
def Get_Int():
'''
返回随机数1-100
'''
from random import randint as rand
return rand(1,101)
#有参数无固定类型
def Get_MaxInt(MaxInt):
'''
返回1至最大的随机数
'''
from random import randint as rand
return rand(1,MaxInt)
#有参数固定类型
def Get_Min_Max(Min:int, Max:int):
'''
返回最小值和最大值之间的随机数\r\n
需要int类型
'''
from random import randint as rand
return rand(Min,Max + 1)
#有参数可不输入
def Get_Min_Max_par(Min = 1, Max:int = 1000):
'''
可输入参数或不输入
'''
return Function.Get_Min_Max(Min,Max)
#多参数
def GetPrints(*mag):
'''
无返回值
'''
for i in mag:
print(i)
#指定类型 根据key value 这种形式
def Get(**key):
if(key is dict):
print(type(key))
#测试时执行
#引入时不执行
if __name__ == '__main__':
p1 = Person('a')
print(p1.name)
print(p1.GetMoney())
p2 = Mods()
print(p2.name)
print(p2.value)
#参数调换
print(Function.Get_Min_Max(Max = 1000,Min = 1))
Function.GetPrints(1,2,3)
引用自定义函数.py
#引入模块(在同一目录)
from Module import Person as per
from Module import Mods as mod
#必须有参数
print(per('a').GetMoney())
#没有函数
p1 = mod()
print(p1.name)
'''
输出
2020
NaNa
'''