1、函数参数
>>> # 对于函数内不可修改的类型:元组、int、字符串 >>> # 通过将值防止在列表中解决不可变 >>> def inc(x): x[0]=x[0]+1 ... >>> foo = [10] >>> inc(foo) >>> foo [11] >>> def change(n): n= 'new' >>> name = 'old' >>> change(name) >>> name 'old'
2、关键字参数
>>> def hello(greeting,name): print '%s, %s' % (greeting,name) >>> hello('hello','world') hello, world >>> hello(name='world',greeting='hello') hello, world
3、收集参数
>>> def print_params(*params): print params >>> print_params('Test') ('Test',) >>> print_params(1,2,3) (1, 2, 3) >>> # 收集关键字参数会出错 >>> print_params(params='123') Traceback (most recent call last): File "<pyshell#32>", line 1, in <module> print_params(params='123') TypeError: print_params() got an unexpected keyword argument 'params' >>> # 使用**收集关键字参数为字典 >>> def print_params2(*params1,**params2): print params1 print params2 >>> print_params2(1,2,3,p1=3,p2=2) (1, 2, 3) {'p2': 2, 'p1': 3}
4、反转过程(与收集参数反转)
>>> def add(x,y):return x+y >>> params = (1,2) >>> add(*params) 3 >>> params = {'name':'jason', 'greeting':'hello'} >>> hello(**params) hello, jason
相关推荐
Chapter 13: Writing a GUI with Python 209 GUI Programming Toolkits for Python 209 PyGTK Introduction 210 pyGTK Resources 211 Creating GUI Widgets with pyGTK 213 Try It Out: Writing a Simple pyGTK...
《Beginning Python:Using Python 2.6 and Python 3.1》
Beginning Python from Novice to Professional Beginning Python from Novice to Professional
Beginning Python Games Development, Second Edition
Beginning Python Games Development, 2nd Edition will teach you how to create visuals, do event handling, create 3D games, add media elements, and integrate OpenGL into your Python game. In this ...
Updated to reflect the latest in Python programming paradigms and several of the most crucial features found in Python 3, Beginning Python also covers advanced topics such as extending Python and ...
Beginning Python From Novice to Professional(3rd) 英文epub 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Chapter 5: Functions 71 Chapter 6: Classes and Objects 93 Chapter 7: Organizing Programs 111 Chapter 8: Files and Directories 127 Chapter 9: Other Features of the Language 143 Chapter 10: Building a ...
beginning python from novice to professional 源代码,python 基础教程
Python基础教程 Beginning Python From Novice to Professional.zip,收录了 Python基础教程 Beginning Python From Novice to Professional 中英文各版本和源码,包括(第2版)和 (第3版),都有详尽的书签,不是一级...
Beginning python 3.pdf
Beginning Python From Novice to Professional(3rd) Beginning Python From Novice to Professional(3rd)
Beginning Python Visualization(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权...
2015年第二版,Beginning Game Development with Python and Pygame 的新版,Beginning Python Games Development, Second Edition 作者: Will McGugan 出版社: Apress 副标题: With PyGame 出版年: 2015-6-21 ...
“开始Python:使用Python 2.6和Python 3.1引入了这种开源的、可移植的、解释的、面向对象的编程语言,它结合了强大的功能和清晰的语法。本书通过讲授基础知识,使您能够快速创建健壮、可靠和可重用的Python应用程序...
Beginning Python - From Novice To Professional英文原版PDF,可复制,适合入门python
Beginning Python From Novice to Professional(3rd) 英文无水印pdf 第3版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...
python基础教程 (Beginning Python From Novice to Professional) 书中源码例子
Beginning Python From Novice to Professional 3rd Edition by Magnus Lie Hetland
Python 经典英文原版教材,可视化编程教程,适合有一定python编程基础的开发人员使用