'id' 在 Python 中是一个错误的变量名 [英] 'id' is a bad variable name in Python

查看:44
本文介绍了'id' 在 Python 中是一个错误的变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在 Python 中命名变量 id 不好?

Why is it bad to name a variable id in Python?

推荐答案

id() 是一个基本的内置:

关于模块内建函数id的帮助__builtin__:

Help on built-in function id in module __builtin__:

id(...)

    id(object) -> integer

    Return the identity of an object.  This is guaranteed to be unique among
    simultaneously existing objects.  (Hint: it's the object's memory
    address.)

一般来说,在任何语言中使用使关键字或内置函数黯然失色的变量名都是一个坏主意,即使允许也是如此.

In general, using variable names that eclipse a keyword or built-in function in any language is a bad idea, even if it is allowed.

这篇关于'id' 在 Python 中是一个错误的变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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