मेरा संपादक (टेक्स्टमैट) id
को अन्य रंगों में दिखाता है (जब परिवर्तनीय नाम के रूप में उपयोग किया जाता है) तो मेरे सामान्य चर नाम। क्या यह एक खोजशब्द है? मैं छाया किसी भी कीवर्ड नहीं करना चाहते ...क्या `id` पायथन में एक कीवर्ड है?
उत्तर
id
एक कीवर्ड अजगर में नहीं है, लेकिन यह एक built-in function का नाम है।
कीवर्ड 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
कीवर्ड अमान्य चर नाम हैं।
if = 1
दूसरी ओर, बिल्ट-इन कार्य id
या type
या str
की तरह छाया जा सकता है::
str = "hello" # don't do this
यह एक समारोह में बनाया गया है:
निम्नलिखित सिंटैक्स त्रुटि होगा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.)
आप पाइथन से भी सहायता प्राप्त कर सकते हैं:
>>> 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.)
या वैकल्पिक रूप से आप सवाल कर सकते हैं 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.)
धन्यवाद, मैं बस पाइथन में (शक्तिशाली) docu के बारे में भूल गया। :-) – Aufwind
क्या मैं निश्चित रूप से 'मदद (कुछ कमांड)' का उपयोग कर सकता हूं, मुझे यकीन नहीं है, अगर 'कुछ कमांड' एक कीवर्ड या पाइथन अंतर्निहित कार्य सुनिश्चित हो सकता है? – Aufwind
@Aufwind हाँ, आप कर सकते हैं। कीवर्ड के लिए, हालांकि, आपको 'if' कथन' के लिए उदाहरण के लिए एक स्ट्रिंग का उपयोग करना होगा, 'मदद' ('if') '। – joaquin
बस reference purposes के लिए:
चेक अगर कुछ पायथन में एक कीवर्ड है:
>>> import keyword
>>> keyword.iskeyword('id')
False
अजगर के सभी कीवर्ड की जाँच करें:
>>> keyword.kwlist
['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif',
'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import',
'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try',
'while', 'with', 'yield']
त्वरित उत्तर के लिए धन्यवाद। मुझे लगता है कि 'आईडी'' का उपयोग 'वर्ग' में एक विशेषता के रूप में बुरा है? 'myobject = myclass(); myobject.id = 123; 'क्या यह अंतर्निहित फ़ंक्शन भी छाया करेगा? – Aufwind
@Aufwind: वर्ग विशेषता के रूप में 'id' का उपयोग करना उतना बुरा नहीं है, क्योंकि पायथन में आपको हमेशा इसे (' this.id' या 'foo.id') के साथ अर्हता प्राप्त करनी होती है, इसलिए यह हमेशा ''' का पालन करता है। । आपका संपादक इस भेद को समझ नहीं सकता है। –
कीवर्ड को संपादित और जोड़ने के लिए स्वतंत्रता ली। – Trufa