zoukankan      html  css  js  c++  java
  • Python中function(函数)和methon(方法)的区别

    在Python中,对这两个东西有明确的规定:

    函数function —— A series of statements which returns some value to a caller. It can also be passed zero or more arguments which may be used in the execution of the body.

    方法method —— A function which is defined inside a class body. If called as an attribute of an instance of that class, the method will get the instance object as its first argument (which is usually called self).

    从定义的角度上看,我们知道函数(function)就是一系列语句,这些语句返回给调用者一些值或None,它理论上不与其它东西关系,它只需要相关的参数就可以。所以普通的在模块中定义的称谓函数是很有道理的。


    那么方法的意思就很明确了,它是与某个对象相互关联的,也就是说它的实现与某个对象有关联关系。这就是方法。虽然它的定义方式和函数是一样的。

    那明确了两者的区别,那我们怎么让电脑识别是function还是methon

  • 相关阅读:
    数据算法之汉诺塔
    Mvc模板页
    mvc局部视图
    Area区域
    mvc之文件下载
    MVC过滤器
    MVC_Ajax请求
    MVC之校验
    Json&Razor&控制器
    抓包分析,tcpdump 和 wireshark 配合使用的简单尝试
  • 原文地址:https://www.cnblogs.com/richiewlq/p/8072310.html
Copyright © 2011-2022 走看看