तो जैसा की हम जानते हैं कि किसी भी language के program को हम उस language के हिसाब से save करते हैं , उसी तरह से python program को हम हमेशा .py extension के साथ save करते हैं। इस file को हम अपने system में कही भी save कर सकते हैं।

Understanding Python Syntax

  1. so , python program लिखने के लिए आपको किसी भी तरह के tag लगाने की कोई जरूरत नहीं है , जैसे कि other languages like PHP या JavaScript में होता है। आप directly file में coding start कर सकते हैं।

  2. हर Statement के end में semicolon जरूरी नहीं है , अगर आप semicolon नहीं लगाते हैं तो भी कोई problem नहीं है।

  3. python file को हमेशा .py extension के साथ save किया जाता है।

  4. python file run करने से पहले हमें python लिखना जरूरी है।

  5. सबसे ज्यादा ध्यान देने वाली बात है Indentation की , because python program में curly braces का use नहीं किया जाता है। Python में Function , class, loop , और other statement start करने के लिए curly braces {} की जगह colon : का use use किया जाता है।

Python Example

def say_hi(): return "Hi !" print(say_hi())

Output :

python test.py
Hi !

Example में function say_hi() define किया गया है , आप clearly देख सकते हैं कि जहाँ से function start हो रहा वहां colon : का use किया गया है , और function body में जितने भी statement हैं बो एक particular space के बाद लिखे गए हैं।

मतलब किसी भी code of block (function , loop) या class के statements को हमेशा हमेशा define किये जाने वाले function name या class name के बाद space होने चाहिए।

अगर कोई statement आगे पीछे लिख दिया तो पूरे chances हैं कि program में error आएगी।

Some Valid / invalid Syntax

/*Valid*/
print("Hello")
print("World !")
/*Invalid : because second statement has space*/
print("Hello")
 print("World !")
/*Invalid : because all statements should have save space*/
if(True) :
    print("It's True")
  print("OK")

 OR

if(True) :
  print("It's True")
    print("OK")
/*Valid*/
if(True) :
  print("It's True")
else :
  print("It's False")
/*Valid*/
if(True) :
  print("It's True")
else :
      print("It's False")
      print("blah blah..")

इसके अलावा अलावा condition statements में parenthesis () का use भी जरूरी नहीं है , आप directly condition लिख सकते हैं।
For Example :

if 5>2 : print("5 is greater than 2")

Output :

python test.py
5 is greater than 2

I hope, अब आपको python syntax समझ में आ गया होगा।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers