一、函数基础:
函数、关键字、方法之间的区别:
help() id() set() list() dict()
a = []
a.append()
a.insert()
a.extend()
a.pop()
del False True None and or not as break
eg:
def func():
print('*'*100)
func()
pass
return
eg:
a = [1,2,5,88,4,6]
print(a.sort())
return
a = [1,2,4,5,6,88]
eg:
def dream():
print('hello')
return 'world'
print()
'hello'
def dream():
print('hello')
return 'world'
a = dream()
print(a)
'hello'
'world'
二、函数参数:
1.参数类型:
1>.必备参数
def dream('x'):
print('%s'%x)
dream('I Love You')
eg:
def func(a,b):
print('开始')
result = a + b
return result
a = func(1,3)
print(a)
开始
4
2>.默认参数
def func(a,b=100):
result = i + j
return result
c = func(200)
print(c)
300
eg:
def func(a,b=100):
result = i + j
return result
c = func(200,160)
print(c)
360
3>.不定长参数:
def func(*args):
return args
a = func(100,20,300,4,5,6)
print(a)
(100,20,300,4,5,6)
eg:
def func(**kwargs):
print(kwargs)
func(a=1,c=2,b=3)
{'a':1,'c':2,'b':3}
4>.传参顺序
def func(*args,**kwargs):
print(args,kwargs)
func(1,2,3,4,5,a=1,c=2,b=3)
(1,2,3,4,5) {'a':1,'c':2,'b':3}
eg:
def func(a,b,c):
print('hello')
func(1,2,c=3)
hello
eg:
def func(a,b,c):
print('hello')
func(1,b=2,c=3)
hello
eg:
def func(a,*b,**c):
print('hello')
func(1,2,c=3)
hello