• 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>>> 

  • 相关阅读:
    2020面试阿里,字节跳动90%被问到的JVM面试题
    mysql数据库误删恢复
    因用了Insert into select语句,公司报警了
    Spring的Controller是单例还是多例?怎么保证并发的安全
    SpringBoot项目优化和Jvm调优
    java从一个pdf中取出指定页生成一个新的pdf
    java截取出字符串中的所有组数字
    oracle表空间位置迁移
    solr常用操作及集成分词器或cdh集群部署说明
    Oracle中将列查询结果多行逗号拼接成一个大字段
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/6045471.html
Copyright © 2020-2023  润新知