python function parameter
Python 2.7.10 (default, Oct 14 2015, 16:09:02)
[GCC 5.2.1 20151010] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> def function():定义函数
ptintf("run") >>> function() Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
function()
File "<pyshell#2>", line 2, in function
ptintf("run")
NameError: global name 'ptintf' is not defined
>>> def fun():
print ("hello") >>> fun()
hello
>>> def fun2(name):
print(name) >>> fun2(new) Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
fun2(new)
NameError: name 'new' is not defined
>>> fun2("new")
new
>>>
>>>
>>> def fun3(num1,num2):
return num1+num2函数的返回值 >>> print (fun3(1,2))
3
>>> def fun4(name)
SyntaxError: invalid syntax
>>> def fun4(name):
'name is a param'
print(name) >>> fun4("hello world")
hello world
>>> fun4._doc_函数的注释文档 Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
fun4._doc_
AttributeError: 'function' object has no attribute '_doc_'
>>> help(fun4)
Help on function fun4 in module __main__: fun4(name)
name is a param >>> def fun5(*param)
SyntaxError: invalid syntax
>>> def fun5(*param):
print ("%d",len(param))
print (param) >>> fun5(1,2,3,4)
('%d', 4)
(1, 2, 3, 4)
>>> def fun5(*param,par):
print ("%d",len(param))
print (param) SyntaxError: invalid syntax
>>>
>>> def fun6(*param,par):函数的收集参数
print ("%d",len(param))
print (param) SyntaxError: invalid syntax
>>> def fun7(*param,name): SyntaxError: invalid syntax
>>> def fun8(*pa , name1): SyntaxError: invalid syntax
>>>
Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2Type "copyright", "credits" or "license()" for more information.>>> def function():ptintf("run")
>>> function()
Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> function() File "<pyshell#2>", line 2, in function ptintf("run")NameError: global name 'ptintf' is not defined>>> def fun():print ("hello")
>>> fun()hello>>> def fun2(name):print(name)
>>> fun2(new)
Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> fun2(new)NameError: name 'new' is not defined>>> fun2("new")new>>> >>> >>> def fun3(num1,num2):return num1+num2
>>> print (fun3(1,2))3>>> def fun4(name)SyntaxError: invalid syntax>>> def fun4(name):'name is a param'print(name)
>>> fun4("hello world")hello world>>> fun4._doc_
Traceback (most recent call last): File "<pyshell#25>", line 1, in <module> fun4._doc_AttributeError: 'function' object has no attribute '_doc_'>>> help(fun4)Help on function fun4 in module __main__:
fun4(name) name is a param
>>> def fun5(*param)SyntaxError: invalid syntax>>> def fun5(*param):print ("%d",len(param))print (param)
>>> fun5(1,2,3,4)('%d', 4)(1, 2, 3, 4)>>> def fun5(*param,par):print ("%d",len(param))print (param)SyntaxError: invalid syntax>>> >>> def fun6(*param,par):print ("%d",len(param))print (param)SyntaxError: invalid syntax>>> def fun7(*param,name):SyntaxError: invalid syntax>>> def fun8(*pa , name1):SyntaxError: invalid syntax>>>
python function parameter的更多相关文章
- Python Function Note
Python Function Note #汉诺塔问题Python实现 def my_move(n, a, b, c): if n == 1: print(a + ' --> ' + c) el ...
- kwargs - Key words arguments in python function
This is a tutorial of how to use *args and **kwargs For defining the default value of arguments that ...
- python Function
Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "copyright&q ...
- elike.python.function()
将python用于基本的科学计算,能完全替代matlab.就最近写的一个物理模型程序来看,用python建立的物理模型的可控性,代码的层次性都优于matlab,只不过python没有matlab那样的 ...
- PyQt5 Function Parameter Declaration
addWidget self.lcd = QLCDNumber() grid.addWidget(self.lcd,0,0,3,0) grid.setSpacing(10) void QGridLay ...
- python function with variadic arguments or keywords(dict) 可变参数与关键字参数
*args 表示任意个普通参数,调用的时候自动组装为一个tuple **kwags 表示任意个字典类型参数, 调用的时候自动组装成一个dict args和kwags是两个约定俗成的用法. 变长参数可以 ...
- vscode主题开发
vscode主题开发教程 https://blog.csdn.net/Suwanqing_su/article/details/105945290 个人配置结果 主题代码 到Vscode放插件的目录中 ...
- [python] File path and system path
1. get files in the current directory with the assum that the directory is like this: a .py |----dat ...
- An Introduction to Interactive Programming in Python (Part 1) -- Week 2_2 练习
#Practice Exercises for Logic and Conditionals # Solve each of the practice exercises below. # 1.Wri ...
随机推荐
- java多线程系类:JUC线程池:02之线程池原理(一)
在上一章"Java多线程系列--"JUC线程池"01之 线程池架构"中,我们了解了线程池的架构.线程池的实现类是ThreadPoolExecutor类.本章,我 ...
- codevs 2924 数独挑战
2924 数独挑战 http://codevs.cn/problem/2924/ 题目描述 Description "芬兰数学家因卡拉,花费3个月时间设计出了世界上迄今难度最大的数独游戏,而 ...
- Spring源码分析——资源访问利器Resource之实现类分析
今天来分析Spring的资源接口Resource的各个实现类.关于它的接口和抽象类,参见上一篇博文——Spring源码分析——资源访问利器Resource之接口和抽象类分析 一.文件系统资源 File ...
- java并发编程学习: 阻塞队列 使用 及 实现原理
队列(Queue)与栈(Stack)是数据结构中的二种常用结构,队列的特点是先进先出(First In First Out),而Stack是先进后出(First In Last Out),说得通俗点: ...
- FPGA与simulink联合实时环路系列—开篇
FPGA与simulink联合实时环路系列—开篇 作为网络上第一个开源此技术,笔者迫不及待地想将此技术分享出来,希望大家多多支持.笔者从2011年接触FPGA以来,从各个方面使用FPGA,无论是控制. ...
- iOS常用 --- NSDictionary 与 NSMutableDictionary
一.NSDictionary 字典的两种创建方法 NSDictionary *dic1 =[[NSDictionary alloc]init]; 2 // 或: 3 NSDictionary *dic ...
- 解析 XML
解析 XML 文档: 下面的代码片段把 XML 文档解析到 XML DOM 对象中: if (window.XMLHttpRequest){// code for IE7+, Firefox, Chr ...
- Vue.js之v-for
v-for标签可以用来遍历数组,将数组的每一个值绑定到相应的视图元素中去,此外,v-for还可以遍历对象的属性,并且可以和template模板元素一起使用. 一.迭代数组 html: <ul&g ...
- 无法加载父级样式或设置IIS的asp站点启用父路径
打开IIS 1.单击站点,在"IIS"区域中找到ASP图标,双击. 2.找到"启用父路径"项目,将对应的值设置为"TRUE"即可. 顶
- 关于IE8兼容svg图片问题解决
参考 http://www.zhangxinxu.com/wordpress/2013/09/svg-fallbacks/ 对博主表示感谢,详述请参考上述链接 直接把代码复制过来了,备份记录下 < ...