Python Syntax Execution

Python me kisi bhi code ko execute karne ke 2 tarike hain. Pahla aap command prompt/IDLE ka use kariye ya fir direct .py extension ke sath file banakar use run kariye. Chaliye IDLE ka use karke Syntax dekhte hain…

>>> print(“Hello”)
Hello
>>> 

Python Indentation Kya hota hai?

Python me Indentation ka bahut bada role hota hai. Dekha jaye to indention ek space ke alawa kuch bhi nhi h lekin python ke case me ispar dhyan dena bhut hi important hota hai. Indentation kisi bhi line of code ke pahle ka space hota h. Chaliye hum isse example ke sath samjhege.

Example 1 :

if (8> 4):
print(“8 is greater than 4”)

Example 2 :

if (8> 4):
    print(“8 is greater than 4”)

Upar diye gaye dono examples me se Example 2 “Right” and Example 1 “Wrong” hai. Aisa issliye kyuki “print” ke pahle indentation hona bahut jaruri hai. Ek Indentation keyboard ke tab space ke barabar hota hai. 

Agar aapne C, C++, Java ya inki tarah kisi aur languages me kam kiya hai to aap isse aisa samajhiye ki jaise hum kisi bhi loop me curly braces ka use karte hain usi tarah python me Indentation ka concept hota hai, bas fark itna hai ki hume dusre languages me opening braces aur closing braces ka achi tarah se dhyan dena padta hai lekin Python ke Indentation ke concept ne isse easy kar diya hai.