Python शिकताना पहिला program हा फक्त "Hello, World!" print करण्यापुरता विषय नाही. या छोट्या program मधून Python code कसा लिहिला जातो, statement म्हणजे काय, print() कसे काम करते, comments कशासाठी वापरतो, indentation का महत्त्वाची आहे आणि एका basic Python program ची structure कशी तयार होते हे समजते.
या chapter मध्ये आपण Python program लिहिण्याची foundation मजबूत करणार आहोत.
Current version note: या course साठी stable Python 3 series वापरा. September 6, 2026 रोजी Python 3.14.7 हा latest stable Python 3 release आहे; Python 3.15.0 अजून release candidate stage मध्ये असून final release October 1, 2026 साठी planned आहे.
Learning Outcomes#
हा chapter पूर्ण झाल्यानंतर तुम्ही:
- स्वतःचा basic Python program लिहू शकाल.
print()function वापरून output display करू शकाल."Hello, World!"program मधील प्रत्येक भाग explain करू शकाल.- Python statement म्हणजे काय हे ओळखू शकाल.
- comments योग्य ठिकाणी वापरू शकाल.
- indentation चा Python मध्ये असलेला विशेष role explain करू शकाल.
- indentation चुकीची असल्यास basic problem identify करू शकाल.
- एका छोट्या Python program ला readable structure मध्ये arrange करू शकाल.
- या concepts वर beginner-level interview questions confidently answer करू शकाल.
1.1 तुमचा पहिला Python Program#
Imagine करा, तुम्ही Python install केले आहे आणि आता computer ला पहिली instruction द्यायची आहे:
Screen वर Hello, World! दाखव.
Python मध्ये:
print("Hello, World!")Expected Output:
Hello, World!हा पूर्णपणे valid Python program आहे.
Java किंवा इतर काही languages प्रमाणे basic output दाखवण्यासाठी class, main() method किंवा अनेक lines ची boilerplate structure लिहिण्याची आवश्यकता नाही.
Python मध्ये अनेक simple programs एका statement पासून सुरू होऊ शकतात.
1.2 print() Function#
Definition: print() is a built-in Python function used to display values or messages as output.
याचा अर्थ, print() हे Python मध्ये आधीपासून उपलब्ध असलेले function आहे ज्याद्वारे आपण screen वर text किंवा इतर values display करू शकतो.
उदाहरण:
print("Welcome to Python")Output:
Welcome to Pythonइथे:
printहे function चे नाव आहे.
(
)या parentheses मध्ये function ला द्यायची माहिती लिहिली जाते.
"Welcome to Python"हा text आहे.
Text ला Python मध्ये quotation marks मध्ये लिहिले जाते. Strings बद्दल आपण पुढील chapters मध्ये व्यवस्थित शिकणार आहोत; सध्या एवढे लक्षात ठेवा की text print करण्यासाठी quotation marks वापरतो.
एकापेक्षा जास्त messages print करणे#
print("Welcome")
print("Python course started")
print("Happy Learning")Output:
Welcome
Python course started
Happy Learningप्रत्येक print() call चा output सामान्यतः नवीन line वर दिसतो.
Numbers print करणे#
print(10)
print(25)Output:
10
25Notice करा:
print("10")आणि:
print(10)दोन्ही screen वर 10 दाखवू शकतात, पण internally त्यांचा अर्थ समान नाही.
पहिल्या example मध्ये "10" हे text आहे.
दुसऱ्या example मध्ये 10 हा numeric value आहे.
Data types पुढील chapter मध्ये शिकू; सध्या हा फरक फक्त observe करा.
Multiple values print करणे#
print() ला multiple values देखील देता येतात.
print("Python", "Beginner", "Course")Output:
Python Beginner CourseDefault behavior मध्ये print() multiple values दरम्यान space दाखवते.
Practical Example#
Suppose तुम्ही simple course information program तयार करत आहात.
print("CodeLangs AI")
print("Python Beginner Course")
print("Chapter: First Python Program")Output:
CodeLangs AI
Python Beginner Course
Chapter: First Python Programयेथे program प्रत्येक statement क्रमाने execute करतो.
Must Know: print() program मधील value बदलत नाही. त्याचे प्राथमिक काम दिलेली माहिती output म्हणून display करणे आहे.1.3 Hello World Program#
Definition: A Hello World program is a minimal program commonly used to verify that a programming environment can successfully run basic code.
Programming शिकताना:
print("Hello, World!")हा सर्वात common first program आहे.
पण त्याचा उपयोग फक्त tradition म्हणून नाही.
समजा तुम्ही:
- Python install केले.
- VS Code configure केले.
.pyfile तयार केली.- Python interpreter select केला.
- program run केला.
आता:
print("Hello, World!")योग्य output देत असेल, तर basic environment काम करत असल्याची पहिली confirmation मिळते.
Program breakdown#
print("Hello, World!")याला parts मध्ये पाहू:
printPython built-in function.
(function call ची opening parenthesis.
"Hello, World!"display करायचा text.
)function call complete करते.
Output:
Hello, World!Code आणि Output वेगळे आहेत#
Beginner ची common confusion:
print("Hello")हा source code आहे.
तर:
Helloहा त्या code चा output आहे.
Output मध्ये print(), parentheses किंवा quotation marks दिसत नाहीत.
1.4 Python Statements#
Definition: A statement is an instruction that Python can execute.
मराठीत सांगायचे तर, statement म्हणजे Python ला दिलेली executable instruction.
उदाहरण:
print("Welcome")ही एक statement आहे.
आणखी एक:
print("Learning Python")ही दुसरी statement आहे.
Program:
print("Welcome")
print("Learning Python")
print("Let's begin")यामध्ये तीन statements आहेत.
Python सामान्यतः program top-to-bottom execute करते.
Execution flow:
Statement 1
↓
Statement 2
↓
Statement 3या program मध्ये:
print("Welcome")
print("Learning Python")
print("Let's begin")execution:
print("Welcome")
↓
print("Learning Python")
↓
print("Let's begin")Output:
Welcome
Learning Python
Let's beginStatement order matters#
Compare करा:
Program A#
print("Login successful")
print("Welcome to dashboard")Output:
Login successful
Welcome to dashboardProgram B#
print("Welcome to dashboard")
print("Login successful")Output:
Welcome to dashboard
Login successfulदोन्ही programs technically valid आहेत.
पण statements चा order बदलल्यामुळे output order बदलला.
यातून एक fundamental principle समजतो:
Program म्हणजे फक्त instructions चा collection नाही; त्या instructions कोणत्या क्रमाने execute होतात हे देखील महत्त्वाचे असते.
प्रत्येक line म्हणजे नेहमी statement असते का?#
नाही.
उदाहरण:
# Display welcome message
print("Welcome")पहिली line comment आहे. ती executable instruction नाही.
दुसरी line executable statement आहे.
यामुळे code मधील प्रत्येक visible line program action perform करेलच असे नाही.
1.5 Comments#
Definition: A comment is text written in source code for humans that Python normally ignores during execution.
Comment program वाचणाऱ्या developer साठी असतो.
Python code execute करताना comment मधील text instruction म्हणून execute करत नाही.
Single-line comment # ने सुरू करता येतो.
# Display a welcome message
print("Welcome")Output:
WelcomeComment output मध्ये दिसत नाही.
Comments का वापरायचे?#
Imagine करा तुम्ही आज code लिहिला:
print("Order received")
print("Payment pending")आज तुम्हाला logic माहिती आहे.
पण सहा महिन्यांनंतर किंवा दुसऱ्या developer ने हा code पाहिला तर context लगेच समजेलच असे नाही.
Useful comment:
# Display the current order status
print("Order received")
print("Payment pending")Comment code चा purpose समजण्यास मदत करतो.
Comment वापरून line temporarily ignore करणे#
print("Application started")
# print("Debug mode enabled")
print("Application ready")Output:
Application started
Application readyदुसरे print() comment केले असल्यामुळे execute होत नाही.
याला अनेकदा commenting out code असे म्हणतात.
Good Comment vs Weak Comment#
Weak#
# Print welcome
print("Welcome")Comment code जे स्पष्टपणे सांगतो तेच repeat करतो.
Better#
# Message shown after successful course enrollment
print("Welcome")हा comment context देतो.
Good comments explain useful context or intent. They should not simply translate obvious code into English.
Inline comment#
Python मध्ये statement नंतरही # वापरता येतो.
print("Course Active") # Status shown to enrolled learnersहे valid आहे.
परंतु प्रत्येक line वर inline comments टाकणे आवश्यक नाही.
Readable code ला unnecessary comments ने भरू नका.
Important clarification: # string मध्ये असेल तर?#
print("#Python")Output:
#Pythonइथे #Python quotation marks मध्ये आहे.
म्हणून तो output चा भाग आहे; comment नाही.
Compare:
# Python course
print("Python")पहिली line comment आहे.
1.6 Code Indentation#
Definition: Indentation is the whitespace placed at the beginning of a line, and Python uses it to define groups or blocks of statements.
Python मध्ये indentation फक्त code सुंदर दिसण्यासाठी वापरली जात नाही.
ती language syntax चा meaningful भाग आहे.
Python documentation देखील सांगते की indentation statements group करण्यासाठी वापरली जाते आणि एका basic block मधील lines समान indentation ने लिहिल्या पाहिजेत.
Indentation म्हणजे काय?#
या code कडे पाहा:
print("Hello")print() line च्या अगदी सुरुवातीपासून सुरू होते.
आता:
print("Hello")दुसऱ्या example मध्ये line च्या सुरुवातीला spaces आहेत.
हेच indentation.
Python मध्ये indentation का important आहे?#
काही programming languages blocks दाखवण्यासाठी { } वापरतात.
Python अनेक compound structures मध्ये indentation वापरते.
उदाहरण फक्त concept समजण्यासाठी:
if True:
print("Inside block")
print("Outside block")Output:
Inside block
Outside blockआपण if statement या chapter मध्ये detail मध्ये शिकत नाही. येथे फक्त indentation चे काम समजण्यासाठी example आहे.
Observe:
if True:
print("Inside block")Indented line if च्या block चा भाग आहे.
तर:
print("Outside block")ही त्या block च्या बाहेर आहे.
Visual understanding#
if True:
│
└── print("Inside block")
↑
Indented → belongs to the block
print("Outside block")
↑
Not indented → outside the blockIncorrect indentation#
if True:
print("Hello")Python ला block कुठे आहे हे valid syntax प्रमाणे सांगितले गेलेले नाही.
Typical result:
IndentationErrorयावेळी exact message context आणि Python version नुसार अधिक detail देऊ शकतो, त्यामुळे error चे wording memorize करण्याऐवजी कारण समजून घ्या.
Root Cause: block सुरू केल्यानंतर required statement indented केलेली नाही.
Correct version:
if True:
print("Hello")Inconsistent indentation#
Conceptually wrong formatting:
if True:
print("First")
print("Second")दोन्ही statements एकाच logical block मध्ये असतील तर त्यांची indentation consistent असणे आवश्यक आहे.
Correct:
if True:
print("First")
print("Second")किती spaces वापरायचे?#
Python ecosystem मध्ये सामान्य आणि recommended convention म्हणजे indentation level साठी 4 spaces वापरणे.
Editor मध्ये auto-indent सुविधा वापरणे practical आहे.
Beginner म्हणून:
एका project मध्ये consistent indentation ठेवा आणि block indentation साठी 4 spaces वापरण्याची सवय लावा.
1.7 Basic Python Program Structure#
Definition: Program structure is the logical organization of statements, comments and related code so that a program is understandable and executes in the intended order.
Python च्या प्रत्येक program ला fixed compulsory skeleton आवश्यक नसतो.
एका basic script ची structure अशी असू शकते:
# Program purpose
print("Application started")
print("Processing request")
print("Application completed")Conceptual structure:
Optional useful comments
↓
Executable statements
↓
Statements arranged in logical orderExample: Student Registration Message#
Requirement:
User ला registration process चे stages display करायचे आहेत.
# Display registration process status
print("Student Registration")
print("Validating details")
print("Registration successful")Output:
Student Registration
Validating details
Registration successfulया छोट्या program मध्ये:
- comment purpose स्पष्ट करते.
- तीन executable statements आहेत.
- statements logical order मध्ये आहेत.
- indentation unnecessary ठिकाणी वापरलेली नाही.
- output readable आहे.
हीच basic program organization ची सुरुवात आहे.
2. Practical / Real-World Application#
Beginners अनेकदा विचारतात:
"print() real project मध्ये खरंच वापरतात का?"हो, पण usage context वर अवलंबून असतो.
print() introductory learning साठी अत्यंत useful आहे आणि छोटे scripts/debugging experiments मध्येही वापरता येते.
उदाहरण:
Suppose software flow चा basic prototype बनवत आहोत:
print("Starting payment process")
print("Checking payment request")
print("Payment process completed")Output:
Starting payment process
Checking payment request
Payment process completedActual production applications मध्ये sophisticated logging systems वापरले जाऊ शकतात. पण logging हा या chapter च्या scope बाहेर आहे.
सध्या महत्त्वाचे learning:
Program starts
↓
Statement executes
↓
Output appears
↓
Next statement executesRealistic Mini Program#
Requirement:
एका online course application मध्ये learner ला basic enrollment progress दाखवायचा आहे.
# Course enrollment status
print("Course: Python Beginner")
print("Enrollment request received")
print("Enrollment successful")
print("You can start learning now")Output:
Course: Python Beginner
Enrollment request received
Enrollment successful
You can start learning nowआपण काय वापरले?#
#→ commentprint()→ output- multiple statements → sequential execution
- meaningful order → readable flow
- no unnecessary indentation → correct top-level structure
एका छोट्या program मध्ये chapter मधील अनेक fundamentals वापरले गेले.
3. Common Mistakes & Misconceptions#
Mistake 1 — print आणि print() समान समजणे#
Incorrect for displaying a message:
printExpected function call:
print("Hello")Root Cause#
Function चे नाव आणि function call यातील फरक न समजणे.
Prevention#
print() वापरताना parentheses आवश्यक आहेत.
Mistake 2 — Text quotation marks शिवाय लिहिणे#
Incorrect:
print(Hello)Beginner ला वाटू शकते की Python screen वर Hello print करेल.
पण Python quotation marks नसलेल्या Hello कडे plain text म्हणून पाहत नाही.
Correct:
print("Hello")या chapter मध्ये variables शिकत नसल्यामुळे यापुढील internal meaning येथे expand करत नाही.
Mistake 3 — Output मध्ये quotation marks दिसतील असे समजणे#
Code:
print("Python")Output:
PythonNot:
"Python"Quotation marks source code मध्ये text delimit करण्यासाठी आहेत.
Mistake 4 — Comment execute होईल असे समजणे#
# print("Hello")यामुळे output येत नाही.
कारण पूर्ण line comment झाली आहे.
Mistake 5 — # कुठेही दिसला म्हणजे comment#
print("#Python")येथे #Python string content आहे.
Output:
#PythonMistake 6 — Indentation फक्त formatting आहे#
हा गंभीर misconception आहे.
Python मध्ये indentation program structure define करू शकते.
Incorrect indentation मुळे:
- syntax-related error येऊ शकतो,
- statement चुकीच्या block मध्ये जाऊ शकतो,
- program चा intended flow बदलू शकतो.
Mistake 7 — प्रत्येक line ला indentation देणे#
Top-level program:
print("Start")
print("End")याला random spaces देणे चांगली formatting नाही.
Indentation फक्त logical structure नुसार वापरा.
Misconception — प्रत्येक Python program ला fixed main() आवश्यक आहे#
Basic Python script लिहिण्यासाठी compulsory main() method आवश्यक नाही.
हा valid complete script आहे:
print("Hello")Larger Python applications मध्ये developers वेगवेगळ्या structures वापरतात, पण त्या या introductory chapter च्या scope बाहेर आहेत.
4. Hands-On Practice#
Practice 1 — Course Welcome Program#
Requirement#
तीन lines display करा:
Welcome to CodeLangs AI
Python Beginner Course
Learning StartedLearner Task#
स्वतः code लिहा.
Hint 1#
प्रत्येक output line साठी print() वापरू शकता.
Hint 2#
Text quotation marks मध्ये लिहा.
Solution#
print("Welcome to CodeLangs AI")
print("Python Beginner Course")
print("Learning Started")Explanation#
तीन independent statements top-to-bottom execute होतात.
Practice 2 — Add a Useful Comment#
Given:
print("Order confirmed")
print("Preparing order")Task#
Program चा purpose explain करणारा useful comment पहिल्या line च्या आधी लिहा.
Solution#
# Display order processing status
print("Order confirmed")
print("Preparing order")Practice 3 — Predict the Output#
print("Step 1")
# print("Step 2")
print("Step 3")तुमचा answer आधी ठरवा.
Solution#
Step 1
Step 3Step 2 असलेली line comment आहे.
Practice 4 — Fix the Problem#
if True:
print("Python")if चे detailed behavior शिकण्याची गरज नाही.
Task फक्त indentation fix करणे आहे.
Solution#
if True:
print("Python")Practice 5 — Build a Small Program#
Requirement#
एका learner चा course-start screen तयार करा.
Output:
Python Beginner Course
Chapter 1 completed
Starting First Python ProgramProgram च्या वर एक meaningful comment असावा.
Solution#
# Display learner course progress
print("Python Beginner Course")
print("Chapter 1 completed")
print("Starting First Python Program")5. Interview Preparation#
Q1. What does the print() function do in Python?
Answer: print() is a built-in Python function used to display values or messages as output.
What the interviewer is testing: Whether you understand the purpose of one of Python's most basic built-in functions.
Common weak answer: "print() prints code."
It displays the values passed to it; it does not print or execute arbitrary source code.
Q2. What is a Python statement?
Answer: A statement is an instruction that Python can execute. For example, print("Hello") is a statement that calls the print() function.
Q3. What is a comment in Python?
Answer: A comment is text intended primarily for people reading the source code. A single-line comment commonly starts with #, and Python ignores that comment during normal execution.
Q4. What is the purpose of comments?
Answer: Comments can explain intent, provide useful context, document important reasoning, or temporarily prevent a line of code from executing when the line is commented out.
A good comment should add useful information instead of simply repeating obvious code.
Q5. Is indentation optional in Python?
Answer: No. Indentation is syntactically significant when Python uses it to define a block of statements. Incorrect or inconsistent indentation can cause errors or change the logical structure of code.
Q6. Why is indentation important in Python?
Answer: Python uses indentation to group statements into blocks. Therefore, indentation represents program structure rather than being only a formatting preference.
Q7. What is commonly used for one indentation level in Python?
Answer: Four spaces are the commonly recommended indentation style.
Q8. What is the output of this code?
print("Python")Answer:
PythonThe quotation marks are part of the source syntax used to represent text; they are not displayed by print() in this example.
Q9. What is the difference between source code and output?
Answer: Source code is the set of instructions written by the programmer. Output is the result produced when those instructions execute.
For example:
print("Hello")is source code, while:
Hellois its output.
Q10. Does every Python program require a main() method?
Answer: No. A simple Python script can execute top-level statements directly and does not require a mandatory main() method.
Q11. What happens to this line?
# print("Hello")Answer: It is treated as a comment, so the print() call does not execute.
Q12. Is # always interpreted as the start of a comment?
Answer: No. If # occurs inside a string literal, it is part of the string.
Example:
print("#Python")produces:
#Python6. Quick Revision#
| Concept | Remember |
|---|---|
print() | Displays values/messages |
| Hello World | Minimal program often used to verify basic setup |
| Statement | Instruction Python can execute |
| Comment | Human-readable source text normally ignored during execution |
# | Starts a single-line comment when used outside a string |
| Indentation | Helps define Python code blocks |
| Recommended indentation | Commonly 4 spaces per level |
| Execution order | Basic sequential statements run top-to-bottom |
| Source code | Instructions written by developer |
| Output | Result produced by running code |
Essential Example#
# Display course information
print("Python Beginner Course")
print("First Python Program")Output:
Python Beginner Course
First Python Program7. You Should Now Be Able To#
तुम्ही आता independently:
print()वापरून output display करू शकता.- basic Hello World program लिहू शकता.
- statement identify करू शकता.
- multiple statements चा execution order explain करू शकता.
- useful comments लिहू शकता.
- comment आणि string मधील
#यातील फरक ओळखू शकता. - indentation चा basic purpose explain करू शकता.
- obvious indentation mistake identify आणि fix करू शकता.
- source code आणि output distinguish करू शकता.
- readable basic Python script तयार करू शकता.
- introductory interview questions answer करू शकता.
8. Final Challenge#
Scenario#
तुम्ही एका online learning application चा basic prototype तयार करत आहात.
Learner ने Python course उघडल्यानंतर खालील output दाखवायचा आहे:
CodeLangs AI
Python Beginner Course
Course access verified
Learning session startedConstraints#
तुमच्या program मध्ये:
- एक meaningful comment असावा.
- चार output statements असाव्यात.
- statements logical order मध्ये असाव्यात.
- unnecessary indentation नसावी.
- text योग्य quotation marks मध्ये असावा.
Learner Task#
Solution पाहण्यापूर्वी complete program स्वतः लिहा.
Hint#
Program चा purpose comment मध्ये लिहा आणि प्रत्येक output message साठी print() वापरा.
Solution#
# Display course access and learning session status
print("CodeLangs AI")
print("Python Beginner Course")
print("Course access verified")
print("Learning session started")Reasoning#
Program मध्ये:
- comment program चा purpose सांगते.
- प्रत्येक
print()executable statement आहे. - statements वरून खाली logical order मध्ये execute होतात.
- top-level statements असल्यामुळे unnecessary indentation नाही.
- output आणि source code स्पष्टपणे वेगळे आहेत.