Skip to content

Abstract #9

Description

@eziceice

抽象

  • 文档化函数.在Python中除了添加注释以外(#开头),也可以在函数的开头写下字符串,它就会作为函数的一部分进行储存,这被称为文档字符串.同时,Python内置的help()函数可以得到关于函数的一些有用的信息,具体如下.
def test(name):
    'this is a test'

print(test.__doc__)

print('***')

help(test)

#输出结果
this is a test
***
Help on function test in module __main__:

test(name)
    this is a test
  • 所有的函数的确都有返回值,当函数中没有存在返回值的时候,就返回None.

  • 类似于Java,函数的参数如果是基本类型(字符串,数字以及元组),则传入的实际上为拷贝的值,在函数内改变该参数的值并不会影响原来的参数.而当传入Object或者list之类的时候,在其中改变参数的值会影响原来的list或者object.如果不想对该类参数进行修改,可以使用切片或者deepcopy().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions