Python in Hindi - Keywords | Python Tutorials by Coding Guru

 Python in Hindi - Keywords | Python Tutorials by Coding Guru

Python Tutorial in Hindi: Python in Hindi Python Tutorial For Beginners In Hindi Basic Syntax Python Program in Hindi Script Mode Programming with python in hindi Python Identifiers in Hindi Reserved Words with python in Hindi Lines and Indentation in python In Hindi Multi-Line Statements in Hindi Quotation with Python in Hindi Comments in Python in Hindi Multiple Statement Groups as Suites with python in hindi Command Line Arguments with python in hindi


Table Content

  • Introduction to keywords
  • What is Keywords
  • Keywords in Python
  • Explaination to Keywords in Python

Introduction to Keywords in Python

Python Keyword विशेष Reserve शब्द हैं जो compiler/interpreter के लिए एक विशेष अर्थ व्यक्त करते हैं। प्रत्येक Keyword का एक विशेष अर्थ और एक विशिष्ट Operation होता है। इन keywords को एक variable के रूप में इस्तेमाल नहीं किया जा सकता है। निम्नलिखित पायथन कीवर्ड की सूची है।

TrueFalseNoneandas
assetdefclasscontinuebreak
elsefinallyelifdelexcept
globalforiffromimport
raisetryorreturnpass
nonlocalinnotislambda

कीवर्ड के निम्नलिखित explanation पर विचार करें।

Python Tutorial in Hindi: Python in Hindi Python Tutorial For Beginners In Hindi Basic Syntax Python Program in Hindi Script Mode Programming with python in hindi Python Identifiers in Hindi Reserved Words with python in Hindi Lines and Indentation in python In Hindi Multi-Line Statements in Hindi Quotation with Python in Hindi Comments in Python in Hindi Multiple Statement Groups as Suites with python in hindi Command Line Arguments with python in hindi


  1. True – यह बूलियन true का प्रतिनिधित्व करता है, यदि दी गई स्थिति true है, तो यह “true” लौटाता है। गैर-शून्य मानों को true माना जाता है।
  2. False – यह बूलियन false का प्रतिनिधित्व करता है; यदि दी गई स्थिति false  है, तो यह “false” लौटाता है। शून्य मान को false माना जाता है
  3. None – यह null value या void को दर्शाता है। एक खाली सूची या zero को none के रूप में नहीं माना जा सकता।
  4. And – यह एक Logical operator है। इसका उपयोग कई स्थितियों की जांच करने के लिए किया जाता है। यदि दोनों स्थितियाँ true हैं, तो यह true है। निम्नलिखित truth table पर विचार करें।
ABA and B
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

5. or – यह पायथन में एक logical operator है। यह true है अगर शर्तों में से एक true है। निम्नलिखित truth table पर विचार करें।

ABA and B
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

6. not – यह एक Logical operator है और सत्य मूल्य का विरोध करता है। निम्नलिखित truth table पर विचार करें।

ANot A
TrueFalse
FalseTrue

7. Assert – इस keyword का उपयोग पायथन में debugging tool के रूप में किया जाता है। यह code की correctness की जांच करता है। यदि कोड में कोई error पाई जाती है और यह संदेश को error के साथ print  करता है, तो यह एक AssertionError है ।

Example:

  1. a = 10  
  2. b = 0  
  3. print(‘a is dividing by Zero’)  
  4. assert b != 0  
  5. print(a / b)  

Output:

a is dividing by Zero

Runtime Exception:

Traceback (most recent call last):

  File “/home/40545678b342ce3b70beb1224bed345f.py”, line 4, in  

    assert b != 0, “Divide by 0 error”

AssertionError: Divide by 0 error

8. def – इस keyword का उपयोग python में function को define करने के लिए किया जाता है। यदि function के नाम के बाद के बाद इसका इस्तेमाल किया जाए।

  1. def my_func(a,b):  
  2.     c = a+b  
  3.     print(c)  
  4. my_func(10,20)  

Output:

30

9. class- इसका उपयोग pyhton में class का प्रतिनिधित्व करने के लिए किया जाता है। class वस्तुओं का blueprint है। यह variable और methods का संग्रह है। निम्नलिखित class पर विचार करें।

  1. class Myclass:  
  2.    #Variables……..  
  3.    def function_name(self):  
  4.       #statements………  
 

10. continue – इसका उपयोग वर्तमान पुनरावृत्ति (iteration) के execution को रोकने के लिए किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

  1. a = 0  
  2. while a < 4:  
  3.   a += 1   
  4.   if a == 2:  
  5.     continue  
  6.   print(a)  

Output:

1

3

4

11. break – यह लूप execution और transfer control को लूप के अंत तक समाप्त करने के लिए उपयोग किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. for i in range(5):  
  2.     if(i==3):  
  3.         break  
  4.     print(i)  
  5. print(“End of execution”)  

Output:

0

1

2

End of execution

12. If – इसका उपयोग conditional statement का प्रतिनिधित्व करने के लिए किया जाता है। किसी विशेष block के execution का निर्णय if statement द्वारा किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. i = 18  
  2. if (1 < 12):  
  3. print(“I am less than 18”)  

Output:

I am less than 18

13. Else – if statement के साथ else statement का उपयोग किया जाता है। जब if statement false हो जाता है, तो else ब्लॉक execute किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example:

  1. n = 11  
  2. if(n%2 == 0):  
  3.     print(“Even”)  
  4. else:  
  5.     print(“odd”)  

Output:

Odd

14. elif – इस Keyword का इस्तेमाल कई conditions को check करने के लिए किया जाता है। यह else-if के लिए short form है। यदि पिछली स्थिति false है, तब तक जांच करें जब तक कि true condition न मिल जाए। निम्नलिखित उदाहरण।

Example:

  1. marks = int(input(“Enter the marks:”))  
  2. if(marks>=90):  
  3.     print(“Excellent”)  
  4. elif(marks<90 and marks>=75):  
  5.     print(“Very Good”)  
  6. elif(marks<75 and marks>=60):  
  7.     print(“Good”)  
  8. else:  
  9.     print(“Average”)  

Output:

Enter the marks:85

Very Good

15. del – इसका उपयोग object के reference को हटाने के लिए किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example:

  1. a=10  
  2. b=12  
  3. del a  
  4. print(b)  
  5. # a is no longer exist  
  6. print(a)    

Output:

12

NameError: name ‘a’ is not defined

16. try, except – exceptions को संभालने के लिए try, except का उपयोग किया जाता है। exceptions run-time errors हैं। निम्नलिखित उदाहरण पर विचार करें।

Example:

  1. a = 0  
  2. try:  
  3.    b = 1/a  
  4. except Exception as e:  
  5.    print(e)  

Output:

division by zero

17. raise – raise keyword को exception के माध्यम से forcefully प्रयोग किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. a = 5  
  2. if (a>2):  
  3.    raise Exception(‘a should not exceed 2 ‘)  

Output:

Exception: a should not exceed 2

18. finally  – finally keyword का उपयोग code के एक block को बनाने के लिए किया जाता है जिसे हमेशा execute किया जाएगा चाहे कोई दूसरा block  error उठाता हो या नहीं। निम्नलिखित उदाहरण पर विचार करें।

Example:

  1. a=0  
  2. b=5  
  3. try:  
  4.     c = b/a  
  5.     print(c)  
  6. except Exception as e:  
  7.     print(e)  
  8. finally:  
  9.     print(‘Finally always executed’)  

Output:

division by zero

Finally always executed

19.  for, while  – दोनों keywords पुनरावृत्ति (iteration) के लिए उपयोग किए जाते हैं। for keyword sequences (list, tuple, dictionary, string) पर iterate किया जाता है। जब तक स्थिति false नहीं लौटती है तब तक एक loop execute किया जाता है। निम्नलिखित उदाहरण पर विचार करें।

Example: For loop

  1. list = [1,2,3,4,5]  
  2. for i in list:  
  3.     print(i)  

Output:

1

2

3

4

5

Example: While loop

  1. a = 0  
  2. while(a<5):  
  3.     print(a)  
  4.     a = a+1  

Output:

0

1

2

3

4

20. import – वर्तमान python script में module आयात करने के लिए import कीवर्ड का उपयोग किया जाता है। module में एक runnable python code होता है।

Example:

  1. import math  
  2. print(math.sqrt(25))  

Output:

5

21. from – यह keyword वर्तमान पायथन script में विशिष्ट फ़ंक्शन या attributes को आयात करने के लिए उपयोग किया जाता है।

Example:

  1. from math import sqrt  
  2. print(sqrt(25))  

Output:

5

22. as – इसका उपयोग name alias बनाने के लिए किया जाता है। यह module आयात करते समय user-define नाम प्रदान करता है।

Example:

  1. import calendar as cal  
  2. print(cal.month_name[5])  

Output:

May

23. Pass – pass कीवर्ड कुछ भी नहीं execute या future code के लिए एक placeholder बनाने के लिए प्रयोग किया जाता है। यदि हम एक खाली class या function की घोषणा करते हैं, तो यह एक error दिखाएगा, इसलिए हम pass keyword का उपयोग खाली class या फ़ंक्शन को घोषित करने के लिए करते हैं।

Example:

  1. class my_class:  
  2.     pass  
  3.   
  4. def my_func():   
  5.     pass     

24. return – return कीवर्ड का उपयोग परिणाम मान या कोई भी फ़ंक्शन को वापस करने के लिए किया जाता है.

Example:

  1. def sum(a,b):  
  2.     c = a+b  
  3.     return c  
  4.       
  5. print(“The sum is:”,sum(25,15))  

Output:

The sum is: 40

25. Is – इस keyword का उपयोग यह जांचने के लिए किया जाता है कि क्या दो variables एक ही वस्तु को संदर्भित करते हैं। यह true है अगर वे एक ही वस्तु को संदर्भित करते हैं अन्यथा false निम्नलिखित उदाहरण पर विचार करें।

Example

  1. x = 5  
  2. y = 5  
  3.   
  4. a = []  
  5. b = []  
  6. print(x is y)  
  7. print(a is b)  

Output:

True

False

26. Global – global keyword का उपयोग फ़ंक्शन के अंदर एक global variable बनाने के लिए किया जाता है। कोई भी function global access कर सकता है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. def my_func():  
  2.     global a   
  3.     a = 10  
  4.     b = 20  
  5.     c = a+b  
  6.     print(c)  
  7.       
  8. my_func()  
  9.   
  10. def func():  
  11.     print(a)  
  12.       
  13. func()  

Output:

30

10

27. nonlocal – nonlocal के समान है global (एक function के अंदर function) और nested function के अंदर एक variable के साथ काम करते थे। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. def outside_function():  
  2.     a = 20   
  3.     def inside_function():  
  4.         nonlocal a  
  5.         a = 30  
  6.         print(“Inner function: “,a)  
  7.     inside_function()  
  8.     print(“Outer function: “,a)  
  9. outside_function()  

Output:

Inner function:  50

Outer function:  50

28. Lambda – lamda keyword का उपयोग python में anonymous function को बनाने के लिए किया जाता है। यह एक नाम के बिना एक inline function है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. a = lambda x: x**2  
  2. for i in range(1,6):  
  3.   print(a(i))  

Output:

1

4

9

16

25

29. Yeild – yeild कीवर्ड python जनरेटर के साथ प्रयोग किया जाता है। यह function के execution को रोकता है और call करने वाले को value लौटाता है। निम्नलिखित उदाहरण पर विचार करें।

Example

  1. def fun_Generator():  
  2.   yield 1  
  3.   yield 2  
  4.   yield 3  
  5.   
  6.   
  7. # Driver code to check above generator function   
  8. for value in fun_Generator():  
  9.   print(value)  

Output:

1

2

3

30. With – with keyword exception handling में प्रयोग किया जाता है। यह code को साफ और अधिक पठनीय बनाता है। with उपयोग करने का लाभ , हमें close() को कॉल करने की आवश्यकता नहीं है । निम्नलिखित उदाहरण पर विचार करें।

Example

  1. with open(‘file_path’, ‘w’) as file:   
  2.     file.write(‘hello world !’)    

31. None – none keyword शून्य मान को define करने के लिए उपयोग नहीं किया जाता है। यह याद रखा जाता है कि none 0, गलत या किसी खाली datatype को इंगित नहीं करता है। यह इसके datatype का एक उद्देश्य है, जो निम्नलिखित उदाहरण पर विचार करता है।

Example:

  1. def return_none():  
  2.   a = 10  
  3.   b = 20  
  4.   c = a + b  
  5.   
  6. x = return_none()  
  7. print(x)  

Output:

None

हमने सभी python keyword कवर किए हैं। यह python keyword का संक्षिप्त परिचय है। हम आगामी tutorials में अधिक जानेंगे।

हमें उम्मीद है की आपको हमारा यह लेख Keywords in Python in Hindi जरुर पसंद आया होगा. हमारी हमेशा से यही कोशिश रहती है की readers को Python या किसी भी अन्य विषय के बारे में पूरी जानकारी प्रदान की जाये ताकि आपको आवश्यक जानकारी ढूंढने के लिए किसी दुसरे sites या internet में खोजने की जरुरत ना पड़े। इससे आपके समय की बचत भी होगी और एक ही जगह में आपको पूरी information भी मिल जाएगी. 

Post a Comment

Previous Post Next Post