python基础-函数
2017-07-10 22:22
337 查看
函数
局部变量 和 全局变量
name='Jack' def sayHello(): print('hello, {}'.format(name)) def changeName(sname): name=sname sayHello() changeName('tom') # 这里的name是一个局部变量 sayHello() def changeName2(sname): global name name=sname changeName2("tom") sayHello()
python中传递参数是引用复制
就是传递的是引用的拷贝,不会影响原来的指向
p=5 def test(a): a=1 test(p) print(p)
默认参数
带默认位的参数不能位于没有默认位的参数前面
def testParam(name,greeting='Hello'): print('{}, {}'.format(greeting,name)) testParam('Tom') testParam('Jack','goodmorning')
相关文章推荐
- python基础31[__XXX__函数]
- [Python入门及进阶笔记]Python-基础-函数小结
- 【语言处理与Python】4.3风格的问题/4.4函数:结构化编程的基础/4.5更多关于函数
- Python学习入门基础教程(learning Python)--8.3 字典常用的方法函数介绍
- Python学习入门基础教程(learning Python)--6.4 Python的list与函数
- Python连载系列之Python语法基础2:Python中的函数
- Python基础-函数(function)
- python基础学习-3(函数)
- python基础31[__XXX__函数]
- Python学习入门基础教程(learning Python)--2 Python简单函数设计 .
- Python基础知识(四)--函数
- PYTHON基础学习之操作类的一些函数
- Python基础07 函数
- python基础学习-3(函数)
- Python基础07 函数
- 【Python基础】函数
- Python基础(3):函数
- python 函数基础
- Python修炼--常用字符串、数学函数 分类: python基础学习 2013-06-16 13:23 205人阅读 评论(0) 收藏
- Python学习入门基础教程(learning Python)--2.1 Python下自定义函数 .