← Back to Python Course | Chapter 1: Basics | Lesson 7 of 14

Python Keywords और Identifiers

Keywords वे विशेष शब्द हैं जिन्हें Python पहले से अपने काम के लिए उपयोग करता है, जैसे किसी थिएटर में आरक्षित सीटें। Identifiers वे नाम हैं जो आप अपनी चीज़ों के लिए खुद चुनते हैं, बस किसी आरक्षित सीट पर कब्ज़ा मत कीजिए।

Keywords

Keywords वे शब्द हैं जिन्हें Python interpreter अपनी syntax के लिए आरक्षित रखता है — if, class, for, def और लगभग 30 अन्य — और इनमें से किसी को variable नाम बनाने पर SyntaxError उठता है, क्योंकि interpreter आपके इरादे और अपने व्याकरण में फ़र्क नहीं कर पाता।

उदाहरण: Keywords

python
# 'class' is a reserved keyword
# class = 5  # SyntaxError: invalid syntax
print("keywords cannot be used as variable names")

Identifiers

Identifier वह कोई भी नाम है जो आप variable, function या class के लिए चुनते हैं। जो नाम बताएँ कि वे क्या रखते हैं (x के बजाय user_count), उनसे code खुद अपनी व्याख्या करता है, और वे comments कम हो जाते हैं जो आपको वरना लिखने पड़ते।

उदाहरण: Identifiers

python
user_count = 42
print(user_count)

नामकरण के नियम

Identifiers किसी अक्षर या underscore से शुरू होने चाहिए और उसके बाद केवल अक्षर, अंक और underscores हो सकते हैं — कोई space, hyphen, या $ या @ जैसे symbols नहीं, जिन्हें Python पूरी तरह दूसरी syntax के लिए आरक्षित रखती है।

उदाहरण: Naming Rules

python
_valid_name = 1  # starts with an underscore, which is allowed
name2 = 2  # letters followed by a digit, also allowed
print(_valid_name, name2)

नामों में Case Sensitivity

Python page और Page को दो बिलकुल अलग नाम मानती है, क्योंकि पूरी भाषा में identifier की मिलान case-sensitive होती है।

एक अकेली गलत capitalization NameError bugs का आम स्रोत है, जिसे आँख से पकड़ना उलझन भरा हो सकता है।

उदाहरण: Case Sensitivity in Names

python
page = "lowercase"  # lowercase variable name
Page = "uppercase"  # capitalized name is a completely different variable
print(page)
print(Page)

नामों के सर्वोत्तम तरीके

छोटे-मोटे संक्षिप्त रूपों या एक अक्षर वाले नामों की जगह पूरे, वर्णनात्मक शब्द चुनिए (केवल बहुत अल्पकालिक loop counters जैसे i को छोड़कर), और variables तथा functions के लिए Python की snake_case परंपरा का पालन कीजिए ताकि आपका code बाकी ecosystem के साथ एकसमान पढ़ा जाए।

उदाहरण: Best Practices for Names

python
total_price = 19.99  # descriptive snake_case name for a price value
for i in range(3):  # short name "i" is fine for a throwaway loop counter
    print(i)
print(total_price)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.