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 ...
随机推荐
- iis
IIS架构 1. 概述 为了提高IIS的可靠性,安全性以及可用性,与IIS5.0和以前更早的版本不同,IIS6.0提供了一个全新的IIS架构.这个架构的详细情况如下图所示: ...
- 深入理解JVM内幕(转)
转自:http://blog.csdn.net/zhoudaxia/article/details/26454421/ 每个Java开发者都知道Java字节码是执行在JRE((Java Runtime ...
- Zencart视频教程 Zencart模板制作教程视频 Zencart仿站教程资料
Zen Cart是国外一个免费的.界面友好,开放式源码的购物车软件,是目前外贸行业使用最为广泛的网站程序.本仿站技术需要你有一定的html和css基础,易学易懂,一步一步地教你操作和使用Zen Car ...
- AppBox升级进行时 - Entity Framework的增删改查
AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. Entity Framework新增数据 以新增用户为例,作为对比,先来看下使 ...
- vc++2013中使用MySQL connector/C++ 1.1.4静态链接报错
包含头文件 #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/state ...
- 隐式意图启动一个Activity
隐式意图是通过指定一组动作或者属性实现,主要用于跨应用使用. 1.创建一个意图对象 Intent intent = new Intent(); 2.设置意图过滤器 intent.setAction(& ...
- Javascript读写文件
<script type="text/javascript" language="javascript"> //读文件 function readF ...
- .net项目在linux平台的CI流程(基于Jenkins+mono+jexus)
内容较多,主要分为以下4方面内容: Jenkins的安装部署(centos 7+) .net在linux平台CI流程所需的插件管理&配置 Jenkins配置连接Gitlab(也可使用对应插件连 ...
- Python删除指定时间的文件
import os import time import sys from xml.dom import minidom, Node from xml.dom.minidom import parse ...
- 修改Firefox的User-Agent,伪装修改秘籍
火狐浏览器修改userAgent的办法一: 在火狐浏览器地址栏输入"about:config",按下回车进入设置菜单. 找到"general.useragent.over ...