PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Python Identifiers, Keywords (35 Keywords) and Comments (#) (पायथन आइडेंटिफायर्स, 35 कीवर्ड्स और सिंगल/मल्टी-लाइन कमेंट्स) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Python identifiers name variables, functions, classes, and modules using letters (including Unicode), digits, and underscores (`_`) without starting with a digit, and are strictly case-sensitive with unlimited length. Python 3 (3.8–3.13) reserves 35 hard keywords (`keyword.kwlist`) that cannot be used as identifiers, while single-line comments start with `#` and multi-line documentation uses docstrings or consecutive `#` lines.
अध्याय सार: पायथन में आइडेंटिफायर्स वेरिएबल, फंक्शन, क्लास और मॉड्यूल के नाम होते हैं, जिनमें अक्षर, अंक और अंडरस्कोर (`_`) आ सकते हैं (पर अंक से शुरू नहीं हो सकते), तथा ये केस-सेंसिटिव और असीमित लंबाई के होते हैं। आधुनिक पायथन 3 में 35 आरक्षित कीवर्ड्स (`keyword.kwlist`) हैं; सिंगल-लाइन कमेंट `#` से शुरू होता है और मल्टी-लाइन कमेंट के लिए लगातार `#` या डॉकस्ट्रिंग प्रयुक्त होती है।
Python Identifiers, Keywords (35 Keywords) and Comments (#): Detailed Notes & Architecture (पायथन आइडेंटिफायर्स, 35 कीवर्ड्स और सिंगल/मल्टी-लाइन कमेंट्स)
1. Rules for Valid Python Identifiers (मान्य पायथन आइडेंटिफायर्स के नियम)
[EN] An identifier can contain lowercase/uppercase letters (`a-z`, `A-Z`, plus Unicode letters in Python 3), digits (`0-9`), and the underscore character (`_`), but MUST begin with a letter or `_`—never a digit (`9lives` raises `SyntaxError`). Identifiers are **case-sensitive** (`total`, `Total`, and `TOTAL` are three distinct variables) and have **no maximum length limit** in Python. Special symbols (`$`, `@`, `%`, `-`, spaces) and reserved keywords are forbidden; check validity programmatically via `'name'.isidentifier()`.
[HI] आइडेंटिफायर में अक्षर (`a-z`, `A-Z` तथा Unicode अक्षर), अंक (`0-9`) और अंडरस्कोर (`_`) हो सकते हैं, लेकिन इसकी शुरुआत कभी किसी अंक से नहीं हो सकती (`9lives` अमान्य है)। पायथन आइडेंटिफायर्स **केस-सेंसिटिव** होते हैं (`total` और `Total` अलग हैं) और इनकी अधिकतम लंबाई की कोई सीमा नहीं होती। विशेष चिह्न (`$`, `@`, `-`, स्पेस) और कीवर्ड्स अमान्य हैं; किसी स्ट्रिंग की वैधता `'name'.isidentifier()` से जाँची जा सकती है।
2. Underscore Naming Conventions and Name Mangling (अंडरस्कोर नामकरण परंपराएँ और नेम मैंगलिंग)
[EN] Leading and trailing underscores carry special PEP 8 and interpreter semantics: `_single` signals internal/private use and is skipped by `from module import *`. A double leading underscore (`__attr`) inside a class triggers **name mangling**, rewriting the identifier internally to `_ClassName__attr` to prevent accidental subclass clashes. Double leading and trailing underscores (`__init__`, `__len__`) denote special 'dunder' (magic) methods reserved for Python's data model, while `_` alone conventionally holds throwaway loop values or the last REPL result.
[HI] अंडरस्कोर के उपयोग का विशेष अर्थ होता है: `_var` आंतरिक उपयोग का संकेत देता है और `from mod import *` द्वारा इम्पोर्ट नहीं होता। क्लास के भीतर `__var` (डबल अंडरस्कोर शुरुआत में) **नेम मैंगलिंग** सक्रिय करता है, जिसे पायथन `_ClassName__var` में बदल देता है। `__init__` जैसे दोनों तरफ डबल अंडरस्कोर वाले नाम 'डंडर' (dunder/magic) मेथड्स कहलाते हैं, जबकि अकेला `_` अस्थायी या अनदेखी वैल्यू के लिए प्रयुक्त होता है।
3. 35 Hard Keywords and Soft Keywords (35 हार्ड कीवर्ड्स और सॉफ्ट कीवर्ड्स)
[EN] Standard Python 3 (3.8 through 3.13) defines exactly **35 hard keywords** listed in `keyword.kwlist`, including `False`, `None`, `True`, `and`, `as`, `assert`, `async`, `await`, `break`, `class`, `continue`, `def`, `del`, `elif`, `else`, `except`, `finally`, `for`, `from`, `global`, `if`, `import`, `in`, `is`, `lambda`, `nonlocal`, `not`, `or`, `pass`, `raise`, `return`, `try`, `while`, `with`, and `yield`. Notice that ONLY three (`True`, `False`, `None`) begin with an uppercase letter while the remaining 32 are all lowercase. Python 3.10+ also added context-sensitive **soft keywords** (`match`, `case`, `_`, `type` in `keyword.softkwlist`), which act as keywords only in structural pattern matching or type statements and remain legal variable names elsewhere.
[HI] पायथन 3.8 से 3.13 तक `keyword.kwlist` में ठीक **35 हार्ड कीवर्ड्स** हैं (जैसे `if`, `elif`, `else`, `def`, `class`, `lambda`, `yield`, `async`, `await` आदि)। इनमें केवल तीन (`True`, `False`, `None`) बड़े अक्षर से शुरू होते हैं, जबकि शेष 32 पूरी तरह छोटे अक्षरों (lowercase) में हैं। पायथन 3.10+ में संदर्भ-आधारित **सॉफ्ट कीवर्ड्स** (`match`, `case`, `_`, `type`) जोड़े गए हैं, जो विशेष सिंटैक्स के बाहर सामान्य वेरिएबल नाम भी बन सकते हैं।
4. Single-Line Comments (#) and Docstrings (सिंगल-लाइन कमेंट्स (#) और डॉकस्ट्रिंग्स)
[EN] A Python comment begins with the hash symbol (`#`) outside string literals and continues to the end of that physical line; the interpreter completely ignores comments during tokenization. Unlike C/Java (`/* ... */`), Python has **no dedicated multi-line comment delimiter**—PEP 8 recommends prefixing each comment line with `#`. Unassigned triple-quoted strings (`"""..."""` or `'''...'''`) are string literals rather than true comments: placed as the very first statement of a module, class, or function, they become its **docstring** stored in `__doc__` (accessible via `help()`), and elsewhere they must still obey block indentation rules.
[HI] पायथन में कमेंट `#` (हैश) चिह्न से शुरू होता है और उस लाइन के अंत तक चलता है (`"#abc"` स्ट्रिंग के अंदर `#` कमेंट नहीं माना जाता)। C या Java के `/* ... */` की तरह पायथन में कोई अलग मल्टी-लाइन कमेंट सिंटैक्स नहीं है; मल्टी-लाइन कमेंट के लिए प्रत्येक लाइन पर `#` लगाया जाता है। ट्रिपल कोट्स (`"""..."""`) असल में स्ट्रिंग लिटरल हैं, न कि कमेंट—यदि ये मॉड्यूल, क्लास या फंक्शन के पहले स्टेटमेंट हों तो **डॉकस्ट्रिंग** (`__doc__`) बनते हैं और इन्हें भी सही इंडेंटेशन मानना पड़ता है।
Syntax, Formula & Technical Example (Python Identifiers, Keywords (35 Keywords) and Comments (#))
import keyword
"""Module docstring stored in __doc__."""
user_age_1 = 21 # Valid identifier & inline comment
_internal = True # Keyword True starts with capital T
print(len(keyword.kwlist)) # Prints 35 in Python 3.8+
print("my_var".isidentifier()) # True
print("2var".isidentifier()) # False (cannot start with digit)
Python Identifiers, Keywords (35 Keywords) and Comments (#) Quick Reference & Comparison Table
| Lexical Element | Rule / Count in Python 3 | Important Example / Fact |
|---|---|---|
| Identifiers | Letters (incl. Unicode), digits, _ ; no leading digit | `_count_2` valid; `2count` or `my-var` SyntaxError |
| Hard Keywords | 35 reserved words (keyword.kwlist) | Only True, False, None are capitalized; 32 lowercase |
| Comments (#) | Hash # to end of line; no /* */ syntax | Multi-line comments use # on each line |
| Docstrings (""" """) | First string literal in module/class/def | Stored in __doc__ attribute; must obey indentation |
Python Identifiers, Keywords (35 Keywords) and Comments (#) Top 20 Bilingual MCQs with Answers
Q1. How many hard keywords exist in `keyword.kwlist` in standard Python 3 (3.8 through 3.13)?
(मानक पायथन 3 (3.8 से 3.13) के `keyword.kwlist` में कुल कितने हार्ड कीवर्ड्स होते हैं?)
(A) 42
(B) 35
(C) 31
(D) 33
Correct Answer: (B)
[EN] Python 3.7 had 33 keywords; promoting `async` and `await` to full keywords in Python 3.7/3.8 brought `len(keyword.kwlist)` to 35.
[HI] पायथन 3.8+ में `keyword.kwlist` के अंतर्गत कुल 35 आरक्षित हार्ड कीवर्ड्स होते हैं।
Q2. Which of the following is a VALID Python identifier?
(निम्नलिखित में से कौन-सा एक मान्य (VALID) पायथन आइडेंटिफायर है?)
(A) `2026_total`
(B) `total-amount`
(C) `global`
(D) `_total_2026`
Correct Answer: (D)
[EN] Identifiers may start with `_` or a letter and contain digits; starting with a digit, using `-`, or using a keyword (`global`) is invalid.
[HI] `_total_2026` अंडरस्कोर से शुरू होने के कारण मान्य है; अंक से शुरू होना, `-` का प्रयोग और `global` कीवर्ड अमान्य हैं।
Q3. Which three Python keywords are the ONLY keywords that start with an uppercase letter?
(पायथन के वे केवल तीन कीवर्ड्स कौन-से हैं जो बड़े अक्षर (uppercase) से शुरू होते हैं?)
(A) `Class`, `Def`, `Return`
(B) `Int`, `Float`, `Str`
(C) `If`, `Else`, `While`
(D) `True`, `False`, `None`
Correct Answer: (D)
[EN] Out of the 35 keywords, only `True`, `False`, and `None` are capitalized; all 32 others are lowercase.
[HI] 35 कीवर्ड्स में से केवल `True`, `False` और `None` बड़े अक्षर से शुरू होते हैं; बाकी सभी 32 छोटे अक्षरों में हैं।
Q4. What does `"for".isidentifier()` return in Python 3?
(पायथन 3 में `"for".isidentifier()` क्या आउटपुट देता है?)
(A) `True` (lexical identifier check only; use `keyword.iskeyword()` to exclude keywords)
(B) `False`
(C) `None`
(D) `SyntaxError`
Correct Answer: (A)
[EN] `str.isidentifier()` checks character/start rules only; you must also check `not keyword.iskeyword(s)` to verify a usable variable name.
[HI] `isidentifier()` केवल अक्षर/अंक नियम जाँचता है इसलिए `'for'.isidentifier()` `True` देता है; कीवर्ड जाँचने के लिए `keyword.iskeyword()` उपयोग होता है।
Q5. What happens if you assign `True = 1` or `None = 0` in Python 3?
(पायथन 3 में `True = 1` या `None = 0` असाइन करने पर क्या होता है?)
(A) `NameError`
(B) `SyntaxError: cannot assign to True / None`
(C) `TypeError`
(D) `True` is overwritten as integer `1`
Correct Answer: (B)
[EN] In Python 3, `True`, `False`, and `None` are strict keywords (unlike Python 2 where `None`/`True`/`False` were built-in names).
[HI] पायथन 3 में `True`, `False` और `None` पूर्ण कीवर्ड हैं, इसलिए इन्हें वैल्यू असाइन करने पर तुरंत `SyntaxError` आता है।
Q6. What is the maximum allowed character length of an identifier in Python?
(पायथन में किसी आइडेंटिफायर (वेरिएबल नाम) की अधिकतम अनुमत लंबाई कितनी होती है?)
(A) 31 characters
(B) 255 characters
(C) No fixed length limit (arbitrary length)
(D) 63 characters
Correct Answer: (C)
[EN] Unlike C89 (31 significant characters), Python identifiers can be of any length limited only by memory.
[HI] पायथन में आइडेंटिफायर की लंबाई की कोई निश्चित सीमा नहीं होती (केवल मेमोरी तक असीमित)।
Q7. What does Python do internally when a class defines an attribute starting with two underscores and no trailing underscores, like `__pin` inside `class Bank`?
(जब किसी क्लास `Bank` के अंदर केवल शुरुआत में दो अंडरस्कोर वाला नाम `__pin` बनाया जाता है, तो पायथन आंतरिक रूप से क्या करता है?)
(A) Deletes it from RAM after `__init__`
(B) Converts it into a global constant
(C) Makes it completely unreadable everywhere including inside `Bank`
(D) Name mangling: rewrites it internally to `_Bank__pin`
Correct Answer: (D)
[EN] Double-leading-underscore attributes undergo name mangling to `_ClassName__attr` to prevent accidental collisions in subclasses.
[HI] डबल अंडरस्कोर (`__pin`) पर नेम मैंगलिंग लागू होती है और पायथन उसे आंतरिक रूप से `_Bank__pin` में बदल देता है।
Q8. What is the purpose of `#` in `print("A#B") # display`?
(`print("A#B") # display` में दोनों `#` चिह्नों का क्या व्यवहार होता है?)
(A) Python ignores the whole line
(B) Both `#` symbols start comments, causing a syntax error
(C) The `#` inside quotes is literal string text, while the `#` after `)` starts a comment
(D) The first `#` ends the string early
Correct Answer: (C)
[EN] Comments only start when `#` appears outside string literals.
[HI] स्ट्रिंग कोट्स के अंदर का `#` सामान्य अक्षर रहता है, जबकि कोट्स के बाहर वाला `#` लाइन के अंत तक कमेंट शुरू करता है।
Q9. Does Python have a dedicated `/* ... */` multi-line comment token like C or Java?
(क्या पायथन में C या Java के `/* ... */` जैसा कोई समर्पित मल्टी-लाइन कमेंट सिंटैक्स होता है?)
(A) Yes, `//` starts multi-line comments
(B) No; multi-line comments use `#` on each line (triple quotes create string literals/docstrings)
(C) Yes, `/* ... */` works identically in Python
(D) Yes, `<!-- ... -->` is Python's multi-line comment
Correct Answer: (B)
[EN] Python only defines `#` as a comment delimiter; triple-quoted blocks are parsed as string literals (docstrings if first in a scope).
[HI] नहीं; पायथन में केवल `#` ही वास्तविक कमेंट है, जबकि ट्रिपल कोट्स (`"""..."""`) स्ट्रिंग लिटरल या डॉकस्ट्रिंग होते हैं।
Q10. Where is the docstring of a function `def greet(): """Say hi."""` stored at runtime?
(`def greet(): """Say hi."""` फंक्शन की डॉकस्ट्रिंग रन-टाइम पर कहाँ स्टोर होती है?)
(A) It is completely discarded like `#` comments
(B) In `greet.__str__`
(C) In `greet.__doc__`
(D) In `greet.__comment__`
Correct Answer: (C)
[EN] The first string literal inside a module, class, or function is bound to its `__doc__` attribute.
[HI] मॉड्यूल, क्लास या फंक्शन के पहले स्टेटमेंट के रूप में लिखी गई स्ट्रिंग उसके `__doc__` एट्रीब्यूट में सेव होती है।
Q11. In Python 3.10+, why are `match` and `case` called 'soft keywords' (`keyword.softkwlist`)?
(पायथन 3.10+ में `match` और `case` को 'सॉफ्ट कीवर्ड्स' (`keyword.softkwlist`) क्यों कहा जाता है?)
(A) They will be removed in Python 3.14
(B) They are optional aliases for `if` and `else`
(C) They behave as keywords only inside structural pattern matching and can still be used as variable names elsewhere
(D) They only work inside comments
Correct Answer: (C)
[EN] Soft keywords preserve backward compatibility for existing code that already used `match = ...` or `case = ...` as identifiers.
[HI] सॉफ्ट कीवर्ड्स केवल पैटर्न मैचिंग सिंटैक्स में कीवर्ड जैसा काम करते हैं; सामान्य जगहों पर इन्हें वेरिएबल नाम के रूप में भी उपयोग किया जा सकता है।
Q12. In Python 3, are identifiers containing non-ASCII Unicode letters like `π = 3.14` or `मूल्य = 100` valid?
(क्या पायथन 3 में `π = 3.14` या `मूल्य = 100` जैसे Unicode अक्षरों वाले आइडेंटिफायर्स मान्य हैं?)
(A) No, only 7-bit ASCII `a-z` and `A-Z` are permitted
(B) Only inside string literals, never as variable names
(C) Only on Windows systems
(D) Yes, Python 3 supports Unicode identifier characters (PEP 3131)
Correct Answer: (D)
[EN] PEP 3131 added full Unicode letter support to Python 3 identifiers (unlike Python 2 which restricted identifiers to ASCII).
[HI] हाँ, PEP 3131 के तहत पायथन 3 आइडेंटिफायर्स में Unicode अक्षरों (जैसे देवनागरी या ग्रीक अक्षर) की अनुमति देता है।
Q13. Which of the following IS a reserved Python keyword (not a soft keyword or built-in function name)?
(निम्नलिखित में से कौन-सा एक आरक्षित पायथन हार्ड कीवर्ड है (न कि सॉफ्ट कीवर्ड या बिल्ट-इन फंक्शन)?)
(A) `match`
(B) `int`
(C) `print`
(D) `lambda`
Correct Answer: (D)
[EN] `lambda` is a hard keyword; `print` and `int` are built-in names (can technically be shadowed, though bad practice), and `match` is a soft keyword.
[HI] `lambda` एक हार्ड कीवर्ड है; `print` और `int` बिल्ट-इन नाम हैं (कीवर्ड नहीं) और `match` सॉफ्ट कीवर्ड है।
Q14. What happens when you write `from mymod import *` if `mymod` defines `_secret = 42` and `public_val = 10` (without `__all__`)?
(यदि `mymod` में `_secret = 42` और `public_val = 10` हों (और `__all__` न हो), तो `from mymod import *` करने पर क्या होगा?)
(A) Both `_secret` and `public_val` are imported
(B) Only `_secret` is imported
(C) `public_val` is imported, while `_secret` is skipped due to its leading underscore
(D) A `SyntaxError` is raised
Correct Answer: (C)
[EN] Wildcard imports (`*`) ignore names beginning with a single underscore `_` unless explicitly listed in `__all__`.
[HI] `from mymod import *` सिंगल अंडरस्कोर `_` से शुरू होने वाले नामों (`_secret`) को स्वतः छोड़कर केवल `public_val` इम्पोर्ट करता है।
Q15. Why can placing an unassigned triple-quoted string `"""note"""` at the wrong indentation level inside a function cause an error?
(किसी फंक्शन के अंदर गलत इंडेंटेशन पर `"""note"""` लिखने से एरर क्यों आता है?)
(A) Because triple quotes are forbidden inside functions
(B) Because Python rejects more than one quote per function
(C) Because `#` is required before every docstring
(D) Because triple-quoted strings are real string statements parsed by Python, not ignored comments
Correct Answer: (D)
[EN] Unlike `#` comments which the lexer strips, `"""note"""` is a string expression statement that must align with the surrounding block's indentation.
[HI] क्योंकि ट्रिपल कोट्स `#` कमेंट की तरह अनदेखे नहीं किए जाते, बल्कि एक वैध स्ट्रिंग स्टेटमेंट होते हैं जिन्हें ब्लॉक के इंडेंटेशन का पालन करना होता है।
Q16. Which statement about Python identifiers, keywords, and comments is NOT true?
(पायथन आइडेंटिफायर्स, कीवर्ड्स और कमेंट्स के बारे में निम्नलिखित में से कौन-सा कथन सत्य नहीं है?)
(A) `#` creates a single-line comment ignored by the Python interpreter
(B) Identifiers in Python are case-insensitive, so `score` and `Score` refer to the same variable
(C) Identifiers cannot start with a digit `0-9`
(D) Python 3.8+ has 35 hard keywords in `keyword.kwlist`
Correct Answer: (B)
[EN] Python identifiers are strictly case-sensitive (`score` and `Score` are completely separate identifiers).
[HI] पायथन आइडेंटिफायर्स पूरी तरह केस-सेंसिटिव होते हैं, इसलिए `score` और `Score` दो बिल्कुल अलग वेरिएबल हैं।
Q17. Within Python Identifiers, Keywords (35 Keywords) and Comments (#), which lexical element directly maps to: "Letters (incl. Unicode), digits, _ ; no leading digit"?
(Python Identifiers, Keywords (35 Keywords) and Comments (#) में कौन सा Lexical Element सीधे "Letters (incl. Unicode), digits, _ ; no leading digit" से संबंधित है?)
(A) Identifiers
(B) Hard Keywords
(C) Comments (#)
(D) Docstrings (""" """)
Correct Answer: (A)
[EN] In Python Identifiers, Keywords (35 Keywords) and Comments (#), 'Identifiers' handles 'Letters (incl. Unicode), digits, _ ; no leading digit' (`_count_2` valid; `2count` or `my-var` SyntaxError).
[HI] Python Identifiers, Keywords (35 Keywords) and Comments (#) में 'Identifiers' का कार्य/विवरण 'Letters (incl. Unicode), digits, _ ; no leading digit' (`_count_2` valid; `2count` or `my-var` SyntaxError) है।
Q18. Which option accurately describes 'Hard Keywords' in Python Identifiers, Keywords (35 Keywords) and Comments (#)?
(Python Identifiers, Keywords (35 Keywords) and Comments (#) के संदर्भ में 'Hard Keywords' की सही विशेषता कौन सी है?)
(A) Hash # to end of line; no /* */ syntax
(B) First string literal in module/class/def
(C) Letters (incl. Unicode), digits, _ ; no leading digit
(D) 35 reserved words (keyword.kwlist)
Correct Answer: (D)
[EN] 'Hard Keywords' provides '35 reserved words (keyword.kwlist)' — key point: Only True, False, None are capitalized; 32 lowercase.
[HI] 'Hard Keywords' का मुख्य विवरण '35 reserved words (keyword.kwlist)' है (Only True, False, None are capitalized; 32 lowercase)।
Q19. In Python Identifiers, Keywords (35 Keywords) and Comments (#), identify the correct parameter for the specification: "Hash # to end of line; no /* */ syntax".
(Python Identifiers, Keywords (35 Keywords) and Comments (#) में "Hash # to end of line; no /* */ syntax" विवरण किस विकल्प के लिए सही है?)
(A) Hard Keywords
(B) Comments (#)
(C) Docstrings (""" """)
(D) Identifiers
Correct Answer: (B)
[EN] 'Comments (#)' corresponds to 'Hash # to end of line; no /* */ syntax' (Multi-line comments use # on each line).
[HI] 'Comments (#)' का संबंध 'Hash # to end of line; no /* */ syntax' (Multi-line comments use # on each line) से है।
Q20. Considering Python Identifiers, Keywords (35 Keywords) and Comments (#), what key behavior defines 'Docstrings (""" """)'?
(Python Identifiers, Keywords (35 Keywords) and Comments (#) में 'Docstrings (""" """)' की मुख्य भूमिका या मान क्या है?)
(A) Hash # to end of line; no /* */ syntax
(B) First string literal in module/class/def
(C) Letters (incl. Unicode), digits, _ ; no leading digit
(D) 35 reserved words (keyword.kwlist)
Correct Answer: (B)
[EN] 'Docstrings (""" """)' represents 'First string literal in module/class/def' (Stored in __doc__ attribute; must obey indentation).
[HI] 'Docstrings (""" """)' का अर्थ/मान 'First string literal in module/class/def' है (Stored in __doc__ attribute; must obey indentation)।
Python Identifiers, Keywords (35 Keywords) and Comments (#) — Exam FAQs
Q1: Why is `int` or `print` not in Python's 35 keywords?
`int` या `print` पायथन के 35 कीवर्ड्स में क्यों शामिल नहीं हैं?
[EN] `int` and `print` are built-in identifiers (in the `builtins` module), not language keywords. Technically you could write `print = 5` (though doing so shadows the built-in function and should be avoided), whereas writing `for = 5` is a `SyntaxError`.
[HI] `int` और `print` बिल्ट-इन नाम (`builtins`) हैं, भाषा के कीवर्ड नहीं; कीवर्ड (`for`, `def`, `True`) वेरिएबल नाम बिल्कुल नहीं बन सकते।
Q2: How can I check the exact list of keywords in my installed Python version?
अपने इंस्टॉल किए गए पायथन वर्जन के सभी कीवर्ड्स की सटीक सूची कैसे देखें?
[EN] Run `import keyword; print(keyword.kwlist)` (and `keyword.softkwlist` for soft keywords in Python 3.10+).
[HI] `import keyword; print(keyword.kwlist)` चलाकर सभी 35 कीवर्ड्स की सूची और `keyword.softkwlist` से सॉफ्ट कीवर्ड्स देखे जा सकते हैं।
Q3: What is the difference between a `#` comment and a docstring?
`#` कमेंट और डॉकस्ट्रिंग में क्या मुख्य अंतर है?
[EN] A `#` comment is completely discarded by the parser and invisible at runtime, whereas a docstring (`"""..."""`) placed as the first statement of a module, class, or function is preserved at runtime in its `__doc__` attribute.
[HI] `#` कमेंट को इंटरप्रेटर पूरी तरह अनदेखा कर देता है, जबकि डॉकस्ट्रिंग (`"""..."""`) रन-टाइम पर ऑब्जेक्ट के `__doc__` एट्रीब्यूट में सुरक्षित रहती है और `help()` में दिखती है।
Post a Comment
Post a Comment