zoukankan      html  css  js  c++  java
  • 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>>> 

  • 相关阅读:
    什么是超参数
    KNN算法(K近邻算法)实现与剖析
    pandas中na_values与keep_default_na
    一篇文章搞懂python2、3编码
    深度学习基础篇之逻辑回归拟合二维数据
    采集万方医药方向的期刊+文章+作者信息(数据量千万级)
    win10安装tensorflow (cpu版)
    内存文件的读写
    海康威视面试python后端题
    Scrapy 采集需要登录注册的网站
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6045471.html
Copyright © 2011-2022 走看看