为什么python在函数调用中需要括号? [英] Why python need parentheses in function call?

查看:40
本文介绍了为什么python在函数调用中需要括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么python不能像其他语言(coffeescript haskell)那样在函数调用中省略括号?只是历史原因还是什么?

Why python can't omit parentheses in a function call just like some other language(coffeescript haskell) do? Just some historical reason or what?

推荐答案

括号允许我们消除函数对象 func 与函数调用 func().

The parentheses allow us to disambiguate the function object, func, from the calling of the function, func().

函数对象是 Python 中的一等对象.例如,您可以将它们作为参数传递给函数,就像任何其他对象一样.这通常用于设置回调函数——GUI 编程或并发编程中的常见做法.

Function objects are first-class objects in Python. You can, for instance, pass them as arguments to functions, just like any other object. This is often used to set a callback function -- a common practice in GUI programming or concurrent programming.

这篇关于为什么python在函数调用中需要括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆