Python सीखने का सबसे अच्छा तरीका है छोटे-छोटे programs लिखना।
इन्हीं छोटे programs की मदद से student syntax, variables, operators, input-output और basic logic को practically समझता है।
इसी तरह जब code को एक file में लिखकर save किया जाता है और फिर run किया जाता है, तो उसे script कहा जाता है।
इसलिए Simple Programs और Scripts programming की शुरुआत का सबसे practical भाग है।
Simple Program क्या होता है
Simple program वह छोटा program होता है जो किसी basic task को perform करता है।
जैसे:
- message print करना
- दो numbers का addition करना
- user se input लेना
- किसी number का square निकालना
ऐसे programs beginners को confidence देते हैं और programming logic की शुरुआत कराते हैं।
सबसे पहला program
Python का सबसे पहला और सबसे common program है:
print("Hello, World!")
Output
Hello, World!
यह program screen पर एक message print करता है।
इसी example से student यह समझता है कि Python code run करने पर output कैसे मिलता है।
Addition program
अब एक simple program देखते हैं जो दो numbers का जोड़ निकालता है।
a = 5
b = 7
sum = a + b
print("Sum =", sum)
Output
Sum = 12
इस program में:
aऔरbvariables हैं+operator addition कर रहा है- result
sumमें store हो रहा है print()output दिखा रहा है
यह example variables और operators को practically clear करता है।
Square of a number
यह भी एक basic beginner-level program है।
n = 4
square = n * n
print("Square =", square)
Output
Square = 16
इस program से student समझता है कि stored value पर operation करके नया result कैसे निकाला जाता है।
User input वाला simple program
Programming में input लेना बहुत important होता है।
Python में input() function की मदद से user से value ली जाती है।
name = input("Enter your name: ")
print("Hello", name)
Example Output
Enter your name: Vedant
Hello Vedant
यह program interactive है, क्योंकि इसमें user से input लिया जा रहा है।
Number input और calculation
जब user से number input लिया जाता है, तो अक्सर उसे integer में convert करना पड़ता है।
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Addition =", a + b)
Example Input
8
3
Output
Addition = 11
यह program दिखाता है कि user input लेकर calculation कैसे की जाती है।
Even or Odd program
यह एक बहुत common beginner program है।
num = int(input("Enter a number: "))if num % 2 == 0:
print("Even Number")
else:
print("Odd Number")
Example Input
6
Output
Even Number
इस program में:
input()से value ली गई%operator remainder check कर रहा हैif-elsedecision ले रहा है
इस प्रकार छोटे programs basic logic building में मदद करते हैं।
Script क्या होती है
जब Python code को किसी file में लिखकर save किया जाता है, तो उसे script कहा जाता है।
Python script की file extension .py होती है।
उदाहरण:
hello.py
अगर इस file में code लिखा हो:
print("Hello, Python")
तो यह एक Python script है।
Script और Shell में अंतर
Python में code दो तरीकों से run किया जा सकता है:
Python Shell
यहाँ code line by line run होता है।
यह testing और quick practice के लिए useful होता है।
Python Script
यहाँ पूरा code file में लिखा जाता है और फिर run किया जाता है।
यह actual programming के लिए ज्यादा useful होता है।
यानी:
- shell → तुरंत test करने के लिए
- script → proper program file के लिए
Script कैसे बनाते हैं
Script बनाने के लिए किसी editor में code लिखा जाता है और file को .py extension के साथ save किया जाता है।
उदाहरण:
student.py
अगर इसमें code हो:
name = "Ravi"
marks = 85
print("Name =", name)
print("Marks =", marks)
तो यह एक valid Python script है।
Script कैसे run करते हैं
Script run करने के लिए command line या terminal में उस file के folder तक जाना होता है।
फिर command दी जाती है:
python student.py
कुछ systems में:
py student.py
यदि file सही है, तो output screen पर दिखाई देगा।
Output
Name = Ravi
Marks = 85
यह process beginners को पूरा flow समझाती है:
- code लिखना
- file save करना
- script run करना
- output देखना
एक complete simple script example
अब एक छोटा complete script example देखते हैं।
# myscript.py
name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Your name is", name)
print("Your age is", age)
Example Output
Enter your name: Aman
Enter your age: 20
Your name is Aman
Your age is 20
यह script input, variable और output—तीनों concepts को एक साथ दिखाती है।
Simple programs क्यों जरूरी हैं
Simple programs beginners के लिए बहुत जरूरी होते हैं, क्योंकि:
- syntax clear होता है
- logic develop होती है
- confidence बढ़ता है
- errors समझ में आते हैं
- script writing की habit बनती है
यही छोटे programs आगे बड़े programs की foundation बनते हैं।
Beginners कौन-सी mistakes करते हैं
Simple programs और scripts लिखते समय beginners अक्सर कुछ common mistakes करते हैं।
कई बार file .py की जगह .txt में save हो जाती है।
कई बार print की spelling गलत हो जाती है।
कई बार input लेते समय number को int() में convert करना भूल जाते हैं।
और कई बार indentation mistake की वजह से error आ जाती है।
इसीलिए शुरुआत में छोटे और साफ programs बार-बार लिखना बहुत जरूरी होता है।
इस topic की मुख्य बात
Simple Programs और Scripts Python programming की practical शुरुआत हैं।
Simple programs की मदद से student output, input, variables, operators और logic को समझता है।
और scripts की मदद से वह proper program file बनाना और run करना सीखता है।
यही part beginner को coding की real practice देता है।