My editor (TextMate) shows id
in another colour (when used as variable name) than my usual variable names. Is it a keyword? I don't want to shade any keyword...
Python id() Function All objects in Python has its own unique id. The id is assigned to the object when it is created. The id is the object's memory address, and will be different for each time you run the program. ( except for some object that has a constant unique id, like integers from -5 to 256)
id() is a function in python, so it's recommend not to use a variable named id. Bearing that in mind, that applies to all functions that you might use... a variable shouldn't have the same name as a function.
1 Answer. The correct answer to the question “Which of the following is not a Keyword in Python” is option (a). Val. As Val is not a correct keyword, in Python and all others are keywords.
Keywords are the reserved words in Python. We cannot use a keyword as a variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language.
You can also get help from python:
>>> help(id) 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.)
or alternatively you can question IPython
IPython 0.10.2 [on Py 2.6.6] [C:/]|1> id?? Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in function id> Namespace: Python builtin Docstring [source file open failed]: 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.)
id
is not a keyword in Python, but it is the name of a built-in function.
The keywords are:
and del from not while as elif global or with assert else if pass yield break except import print class exec in raise continue finally is return def for lambda try
Keywords are invalid variable names. The following would be a syntax error:
if = 1
On the other hand, built-in functions like id
or type
or str
can be shadowed:
str = "hello" # don't do this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With