Loading ...
SeekhoCoding
Python Syllabus Game Python Projects

Chapter 2: Basics Of Python

Python Language के Course को आगे बढ़ाने से पहले आपके लिए Python language के Basics को समझ लेना बहुत जरूरी है क्योंकि Basics आपकी Python Journey की नीव है | इस Web Page पर Python Language का दूसरा chapter (Basics Of Python) add किया गया है | इस Chapter मे आप Python के बहुत महत्वपूर्ण Topics जैसे comment , Variables , Docstring इत्यादि के बारे मे जानेगे |

Identifiers क्या होते है ?

Identifiers वो Names होते है जिनके उपयोग से Memory मे data store and stored data को access किया जाता है | जिस तरह से किसी school मे student से संबंधित information उसके name से पता की जा सकती है , उसी तरह Computer Memory मे Stored data को Identifiers के Names से access किया जाता है |
उदाहरण के लिए , a = 90
90 value को store करने के लिए 90 value को a के name से store किया गया है | अब 90 value को a से access किया जा सकता है |

Identifiers Create करने के Rules

1. Starting = > Identifiers Names को कभी भी digits से declare नही किया जाता है | जैसे = > 8number = 90 digits से Identifiers Names को declare करने पर Python Interpreter error देता है |
2. underscore(_) = > Identifiers Names को declare करते Time Identifier Names के बीच Space का उपयोग नही किया जाता है | Python मे Identifier Names मे Space की जगह underscore (_) का उपयोग किया जाता है जैसे = > numbe_r = 90
3. case-sensitive = > Python एक case sensitive language होने के कारण Identifiers Names case-sensitive होते है यानि कि Number , NUMBER , number तीनो अलग - अलग Identifiers Names है | तीनो Variables का एक दूसरे से कोई संबंध नही है |
4. Keywords = > Python Language मे पहले से ऐसे Words Stored है जिनका मतलब Python के लिए पहले से reserved है , इसलिए Identifier Names को Keywords के Names नही दिए जा सकते है जैसे = > print = 90
5. Special Symbols = > Identifiers के Names मे कभी भी Special Symbol का उपयोग नही किया जाता है | Special symbols जैसे : # , @ , $ etc. ऐसे Symbols का उपयोग करने पर Python Identifiers को मानय नही मानता है |


Keywords क्या होते है ?

Keywords Python Language का एक महत्वपूर्ण Concept है जिसको समझना और जिसका उपयोग करना सरल है | Keywords से मतलब है कि Keywords वे words होते है जिनका Meaning और काम Python Interpreter के लिए पहले से reserved है | हम इनके काम करने के style मे कोई changes नही कर सकते है | जिस तरह से aeroplan का काम air मे उडना है | aeroplan का काम fix है उसको उडना है , उसी तरह से Keywords का भी काम fix है जैसे : print() function का उपयोग screen पर Result show करने के लिए किया जाता है | हम print() function

मे कोई changes नही कर सकते है केवल इसका उपयोग कर सकते है | Python language मे लगभग 35+ Keywords है | आप इन Keywords को पता करने के लिए नीचे दिए गए Code को Python मे run करके पता कर सकते है |

1import keyword
2print(keyword.kwlist) 
    

यह Code क्या करता है ?

उपर दिए गए Code के उपयोग से Python Language मे Available सभी Keywords को पता कर सकते है | इस code की line by line Explanation नीचे दि गई है |
1. import keyword = > Python Language मे पहले से Available keyword Module File को Import किया गया है |
2. print(keyword.kwlist) = > ये print() function keyword file से सभी keywords की list को show करता है |

Types Of Keywords

Python Language मे Mainly Keywords को निम्नलिखित Parts मे devide किया गया है |
1. importing = > कोई Module , file , library etc. को import करने के लिए Python मे importing Keywords का उपयोग किया जाता है from , import , as आदि कुछ importing Keywords के उदाहरण है |
2. Control Flow Keywords = > Python language मे लिखे गए Programs को Control करने के लिए Control Flow keywords का उपयोग किया जाता है if , else , for , while etc. Control Flow keywords है |
3. Exception Handling Keywords = > जब हम Programs लिखते है तो लगभग programs को run करने पर errors आते है , इसलिए errors को handle करने के लिए Exception Handling keywords का उपयोग किया जाता है try , except , finally etc. Exception Handling Keywords है |
4. Operators Keywords = > Python Program मे logics लिखने के लिए Logical Operators Keywords का उपयोग किया जाता है and , or , not etc. Logical operators keywords है | 5. value keywords = > True , False etc. value keywords है |

Keywords Rules

1. Not Identifiers = > Identifiers के names को कभी भी Keywords के Names पर नही रखा जा सकता है जैसे = > if = "User" ऐसे run करने पर error आता है |
2. case sensitive = > Keywords के names भी case-sensitive होते है जैसे print और PRINT दोनों अलग - अलग Keywords है |
3. No Modifications = > जैसा की पहले ही बताया गया की Keywords का मतलब Python मे पहले से ही reserved है यानि की हम keywords के काम मे changes नही कर सकते है |

Advantages Of Keywords

1. reserved Meaning = > क्योंकि keywords का Meaning पहले से reserved है , इसलिए keywords के काम मे changes नही किए जा सकते है |
2. Good performance = > क्योंकि keywords को Python की Team ने Create किया है , इसलिए इनका काम Fix और Smooth होता है |
3. Short Program = > क्योंकि keywords का काम पहले से reserved है , इसलिए हम अधिक long code लिखे बीना keywords के उपयोग से छोटा Program लिखा जाता है |


Variables क्या होते है ?

Data को store करने के लिए variables का उपयोग किया जाता है Varriable एक नाम होता है जिसके अन्दर values store की जाती है | varriable के नाम को एक container के रुप मे समझा जा सकता है | जिस प्रकार किसी डिबे (box) के अन्दर कोई समान रखा (store) जाता है | उसी प्रकार Computer Memory मे Data Store करने के लिए Data को varriables के अन्दर store किया जाता है | यदि हम ऐसे ही Data को memory मे store करते है तो उस Data को access करपाना बहुत कठिन काम हो जाएगा , लेकिन जिस variable मे वो data stored है उस Variable के उपयोग से data पर आसानी से काम किया जा सकता है | Variables मे stored data कोई Text , Number कुछ भी हो सकता है | नीचे कुछ variables मे कुछ values store की गई है |

1a = 15
2b = 1.14
    

a और b varriables है जिनके अन्दर 15 और 1.14 values store की गयी है | |
Python language मे varriable के अंदर value store करने के लिए = (Operator) का उपयोग किया जाता है |

Variables Names Create करने के Rules

Python Programming Language मे Variables को Create करने के लिए कुछ rules का पालन करना पडता है | ये rules नीचे दिए गए है :
1. किसी भी Variable के नाम के बीच मे कोई space ना हो क्योंकि space देने से words parts मे devide हो जाता है और Python को सही Variable के बारे मे नही पता चल पाता है |
2. Variable के names को create करते Time Variable Name मे किसी spacial symbol (# , space, ,@ , comma) का उपयोग नही किया जाता है |
3. varriables के नाम मे space का उपयोग नही किया जाता है , लेकिन अधिक बडा name होने पर Space की जगह underscore (_) का उपयोग किया जाता है |
4. varriables case-sensitive होते है यानि a और A दोनो अलग-अलग variable names है दोनों का एक दूसरे से कोई संबंध नही है |


Constants क्या होते है ?

Constant से अभिप्राय ऐसा variable से है जिसमे changes नही किए जा सकते है | Python मे variables Create जाते है और variables मे values store की जाती है | हम जब चाहे तब Variables मे Stored values को change कर सकते है , लेकिन कुछ ऐसे Programs होते है जिनमे हम variables मे stored values मे changes नही करना चाहते , इसलिए Constant variables ऐसे variables होते है जिनमे changes नही किए जा सकते है | Python Language मे Constant Variables को Create करने के लिए अलग से किसी Keyword का उपयोग नही किया जाता है | Constant Variables को create करने के लिए Variable Names को UPERCASE मे Declare किया जाता है जैसे : NUMBER = 9
NUMBER Variable एक Constant Variable है जिसमे Changes करने की कोशिश नही करनी चाहिए |

Features Of Constant

1. No Need Keyword = > javascript जैसी language मे Constant variables को Create करने के लिए const keyword का उपयोग किया जाता है , लेकिन Python Language मे Constant variable को Create करने के लिए किसी keyword की Need नही होती है |
2. UPERCASE = > क्योंकि Constant Variables को UPERCASE मे Declare किया जाता है यानि capital letters मे जिस कारण दूसरे Programmer को आसानी से पता चल जाता है कि ये एक Constant variable है |
3. Module File = > Large Python Projects मे Constant variables को अलग File मे declare किया जा सकता है फिर इन Constant variables को import keyword के उपयोग से किसी Python File मे उपयोग किया जा सकता है |
4. Example = > NUMBER = 90 NUMBER एक Constant Variable है |


Input Output

Python Language के अन्दर input Output funtion बहुत जरुरी भूमिका निभाते है | किसी भी प्रोग्राम का मेन काम होता है कि वो Program user से कुछ data ले (Input) और बदले मे कुछ data (Output) दे । इसी काम को पूरा करने के लिए Input() Output() functions का उपयोग किया जाता है |
Output
Input के बदले मे मिलने वाला result output कहलाता है मिलने वाला output तभी सही होगा जब input सही होगा यानि की input के गलत होने पर आया output भी गलत होगा | Python Language के अन्दर output के लिए print() का उपयोग किया जाता है | सरल शब्दों output window पर कुछ भी दिखाने के लिए print() का उपयोग किया जाता है नीचे print() Function का एक उदाहरण दिया गया है |

1  print(10)
            
  • Output
  •       10 

    print(10) ये print() function screen पर 10 को show करता है |


    Input
    जो Data user देता है | उसे input कहा जाता है | ये data किसी भी Type (int , float , string) का हो सकता है | Python Language मे user से input लेने के लिए input() उपयोग किया जाता है | नीचे Input() function का एक उदाहरण दिया गया है |

    1  name = input("Enter your name =>")
                
  • Output
  • Enter your name =>shubham

    name = input("Enter your name =>") = > name एक Variable है जो user से input मे value store करता है |


    Docstring (Documentation String)

    documentation लिखने के लिए triple single quotes (''' .... ''') triple double quotes(""" .... """) का इस्तेमाल किया हैं | यानि triple quotes के अन्दर जिस प्रकार String text etc. लिखे जाते है | वो उसी प्रकार print होते है |

    1Print("""
    2Python
    3Is 
    4The
    5Good
    6Language. 
    7""")
    
        
  • Output
  • 
    Python
    is
    the 
    good 
    language.
        

    Escape Characters क्या होते है ?

    Python मे अच्छी Programming , Large Programs को Clean बनाए रखने के लिए Escape Characters का उपयोग किया जाता है | Escape characters का उपयोग तब किया जाता है , जब हमें string के अंदर ऐसे symbol लिखने हों जिनको Normally Python अलग तरीके से समझता है | Python मे Escape Characters backslash(\) से start होते है | Python Language के अंदर उपयोग किए जाने वाले कुछ महत्वपूर्ण Escape Characters नीचे दिए गए है |

    Escape Characters

    1. \n = > backslash n का उपयोग किसी line को दूसरी line मे show करने के लिए किया जाता है यानि \n के उपयोग से line break हो जाती है जैसे :

      print("Hello\nWorld") 
           Output 
      Hello
      World
          

    print("Hello\nWorld") = > ये Print() Screen पर पहली Line मे Hello और दूसरी Line मे World को show करता है |

    2. \t = > backslash t का उपयोग tab जितना space देने के लिए किया जाता है यानि \t के उपयोग से string के बीच tab जितना space आ जाता है जैसे :

      print("Hello\tWorld") 
           Output 
      Hello   World
          

    ये Print() Function Screen पर "Hello" और "World" के बीच 1 tab का space देकर कर Words को show देता है |

    3. \' = > backslash single quote का उपयोग String के बीच single quote show करने के लिए किया जाता है जैसे :

      print('It\'s Python')
           Output 
      It's Python
        

    print('It\'s Python') ये Function Words के बीच Single Quotes(') को show करता है |
    4. \" = > backslash double quote का उपयोग String के बीच double quote show करने के लिए किया जाता है जैसे :

      print("He said \"Hi\"")
           Output 
      He said "Hi"
          

    print("He said \"Hi\"") ये Function Words के बीच Double Quotes(") को show करता है |
    5. \b = > backslash b के उपयोग से पहली value remove होकर पूरी value show होती है | जैसे :

      print("Hello\bWorld")
           Output 
      HellWorld
          

    print("Hello\bWorld") ये Function दोनों words के पहले Word के last Letter को remove करके पूरे Words को show करता है |

    Features Of Escape Characters

    1. Program Clearity = > Escape Characters के उपयोग से लिखे गए Programs Short और समझने योग्य बनते है |
    2. Special Character = > tab , new line जैसे Operations करने के लिए हर तरह के Escape Characters Available है |
    3. Special Meaning = > Python मे Escape Characters का उपयोग करने के लिए \ backslash का उपयोग किया जाता है |


    Indentation In Python

    Python language मे Indentation का मतलब Code की Starting मे दिखाया गया space या tab होता है | Python मे Indentation के बीना Programs लिखने पर Interpreter error देता है जैसे :

    if 5 > 2:
    print("Hello") 
          

    Indentation के बीना Interpreter को ये नही पता चल पाता है कि कोई block कहा से start हो रहा है कहा पर खतम हो रहा है | C++ , C जैसे Language मे code blocks के लिए {} curly Brackets का उपयोग किया जाता है , लेकिन Python मे 1 Tab या 4 Space का उपयोग किया जाता है | नीचे Indentation का एक Example दिया गया है |

    Indentation Example

    def greet():
        print("Hello")
        print("Welcome")
    
    greet()
          

    def greet(): = > greet नाम का एक Function Create किया गया है |
    print("Hello") = > ये print() function "Hello" को show करता है |
    greet() = > greet() function को run करने के लिए function को call की गई है |

    Features Of Indentation

    1. Program Clerity = > Python मे Programs लिखते Time Indentation से Programs समझ आने योग्य और Clear होते है |
    2. Spacing = > Python Language मे Indentation के लिए Normally 4 space या 1 Tab का उपयोग किया जाता है |
    3. Code Block = > Indentation का उपयोग if , else Code Blocks के लिए किया जाता है |
    4. Brackets = > Python Language मे C , C++ जैसी Language के जैसे Indentation के लिए किसी Brackets का उपयोग नही किया जाता है |


    Comments

    अगर user के काम को सरल बनाने की बात हो तो वो comments है | किसी भी code या लाइन को comment करने के बाद वो code या lines Python Interpreter execute नहीं करता है | Python Language के अन्दर Program / line को comment करने के लिए # का उपयोग किया जाता है | किसी लाइन के आगे # लगाने पर वो लाइन comment बन जाती है |
    for example = >

    1# print("hello word")
    2print("hello word")
    3
    4# b = 8
    5# For multiple line comment
    6# select करे फिर ctrl + / press करे |
        
  • Output
  •       hello word
        

    जो - जो lines comment की गई है अब python का Interpreter उन lines को execute / run नही करेगा |

    comments के लाभ

    1. Readability = > किसी बडे Program को समझने के लिए comments बहुत helful है खासकर जो Students coding सिखने की शुरूआत करते है उनके लिए comments बहुत helpful होते है |
    2. Future = > Supose करे की आप एक 200 lines का program लिखते है और फिर कुछ years के बाद उस program को देखते है तो आप उस program के कुछ codes / line को समझ नही पायेगे | तो comments Future मे भी किसी program को समझने मे helpful होते है |
    3. Debugging = > Program मे से error का पता लगाने के बाद program के कुछ part को अलग करने मे helpful है |
    4. Explanations = > बडे - बडे programs को explain करने मे helpful है |
    5. Deffrent Person = > Supose करे की आप अपने program को किसे दूसरे person को देते है तो उसको ये program समझाने के लिए helpful है |

    You have completed This Chapter ! 🎉

    Now you can choose any one of the following options to test your knowledge :

    💻

    Code Practice

    Solve practical exercises .

    Practice Now
    🏆

    Knowledge Test

    Answer the questions of the chapter .

    Start Test
    📘

    Next Chapter

    Continue your Python journey by reading the next chapter.

    Next Chapter
    🆘

    Help Center

    Users and we all help you together .

    Peer Learning
    Expert Advice
    Live Chat
    Fast Solutions