使用名称“功能”对于Python代码中的变量 [英] Using the name "function" for a variable in Python code

查看:125
本文介绍了使用名称“功能”对于Python代码中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python代码中使用函数作为错误样式的参数名称?

Is using the word function for the name of an argument considered bad style in Python code?

def conjunction_junction(function):
    pass # do something and call function in here

此模式始终存在,特别是装饰。您会看到 func fn f 时间,但我喜欢在可能时避免缩写。事实上,它是一个类型的名称,足以保证缩写它?

This pattern occurs all the time, especially in decorators. You see func, fn and f used all of the time but I prefer to avoid abbreviations when possible. Is the fact that it's the name of a type enough to warrant abbreviating it?

>> type(conjunction_junction).__name__
'function'


推荐答案

p>它不是保留的关键字,所以我不明白为什么不。

It's not a reserved keyword, so I don't see why not.

样式指南


如果函数参数的名称与保留关键字冲突,则
通常最好附加一个尾随下划线,而不是
使用缩写或拼写错误。因此class_比
clss更好。 (也许最好是使用同义词避免这种冲突。)

If a function argument's name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than clss. (Perhaps better is to avoid such clashes by using a synonym.)

这篇关于使用名称“功能”对于Python代码中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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