Why is using 'id' as a variable name discouraged in Python?
One should refrain from naming variables id in Python. This is because id() is an integral built-in function that provides a unique identifier for objects within the system's memory.
help(id)
# Output
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.)
Naming a variable id can lead to naming conflicts with the built-in function. Hence, it is generally advisable to avoid using keywords or built-in function names as variable names.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3