一、函数传值
#!/usr/bin/env python
# -*- codinng:utf-8 -*-
# 如何加默认值 默认参数放最左边
def print_info_(sex='male',*args,**kwargs):
print(sex)
print(args)
print(kwargs)
for i in kwargs:
print('%s:%s'%(i,kwargs[i]))
print_info_('female',2,3,45,job='IT',height='188')
'''按顺序传值,female传给sex,2、3、45传给args,job、height键值对传给kwargs'''
def print_info_(sex='male',*args,**kwargs):
print(sex)
print(args)
print(kwargs)
for i in kwargs:
print('%s:%s'%(i,kwargs[i]))
print_info_(2,3,45,'female',job='IT',height='188')
''' 2传给了sex,3、45、female传给了args,键值对传给了kwargs '''
二、return
作用:
- 结束函数
- 返回值
三、函数的作用域
1.遵循LEGB的顺序,这篇博客有详细的讲述
https://www.cnblogs.com/saintdingspage/p/7788958.html
2.变量声明
定义函数时,如果修改全局变量,必须事先声明