函数
1.缺省参数:调用时不需要传参,更加方便
def get_Sum(start=1,end=100):
pass
2.可变数量参数----数量可变
*参数名称----装包,类型是元组
def test(a,b,*args,c=0):
print(a,b,args,c)
test(1,2,3,4,5,c=100) #1 2 (3, 4, 5) 100
test(1, 2, *[10, 20 ,* [55, 66]], c=100) #1 2 (10, 20, 55, 66) 100
3.关键字参数—格式,类型为字典**
def test(a,**kwargs):
print(a,kwargs)
test(1,name = 'tom') #1 {'name': 'tom'}
test(1,**{'name':'tom'}) #1 {'name': 'tom'}
模块和包
'''
#1- 同一个包的
#import 导入的是模块,模块是最小单元
import funLib
funLib.sumFun(1,2)
#2- 不同包
#as 取别名
import moudleTest.mTest as mt
mt.test()
#from xx import xx针对性 导一个用一个,不导入不能使用
#一般对这个模块熟悉
from funLib import sumFun
from moudleTest.mTest import sumFun as mt
sumFun(1,2)
mt(1,2)
import moudleTest
模块搜索规则:
windows->环境变量 path->系统级别的环境path
python解释器—sys.path
import顺序:
1- 当前路径
2- 工程路径
3- 默认路径
包的使用:
import Phone.Mobile.Analog #到模块
from Phone.Mobile import Analog #到模块
from Phone.Mobile.Analog import dial #到函数