Python基础---函数+模块+导包

函数

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 #到函数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值