CodeLangs AISoftware Training Institute
Python for Beginners (Marathi)/First Python Program
Dashboard
Chapter 3 · Python Fundamentals

First Python Program

2,346
words
11
min read
24
practice items
Interactive learning

Practice lab

Question 1 of 12 00:00

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 मध्ये:

PYTHON
print("Hello, World!")

Expected Output:

TEXT
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 करू शकतो.

उदाहरण:

PYTHON
print("Welcome to Python")

Output:

TEXT
Welcome to Python

इथे:

TEXT
print

हे function चे नाव आहे.

TEXT
(
)

या parentheses मध्ये function ला द्यायची माहिती लिहिली जाते.

PYTHON
"Welcome to Python"

हा text आहे.

Text ला Python मध्ये quotation marks मध्ये लिहिले जाते. Strings बद्दल आपण पुढील chapters मध्ये व्यवस्थित शिकणार आहोत; सध्या एवढे लक्षात ठेवा की text print करण्यासाठी quotation marks वापरतो.


एकापेक्षा जास्त messages print करणे#

PYTHON
print("Welcome")
print("Python course started")
print("Happy Learning")

Output:

TEXT
Welcome
Python course started
Happy Learning

प्रत्येक print() call चा output सामान्यतः नवीन line वर दिसतो.


Numbers print करणे#

PYTHON
print(10)
print(25)

Output:

TEXT
10
25

Notice करा:

PYTHON
print("10")

आणि:

PYTHON
print(10)

दोन्ही screen वर 10 दाखवू शकतात, पण internally त्यांचा अर्थ समान नाही.

पहिल्या example मध्ये "10" हे text आहे.

दुसऱ्या example मध्ये 10 हा numeric value आहे.

Data types पुढील chapter मध्ये शिकू; सध्या हा फरक फक्त observe करा.


Multiple values print करणे#

print() ला multiple values देखील देता येतात.

PYTHON
print("Python", "Beginner", "Course")

Output:

TEXT
Python Beginner Course

Default behavior मध्ये print() multiple values दरम्यान space दाखवते.


Practical Example#

Suppose तुम्ही simple course information program तयार करत आहात.

PYTHON
print("CodeLangs AI")
print("Python Beginner Course")
print("Chapter: First Python Program")

Output:

TEXT
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 शिकताना:

PYTHON
print("Hello, World!")

हा सर्वात common first program आहे.

पण त्याचा उपयोग फक्त tradition म्हणून नाही.

समजा तुम्ही:

  1. Python install केले.
  2. VS Code configure केले.
  3. .py file तयार केली.
  4. Python interpreter select केला.
  5. program run केला.

आता:

PYTHON
print("Hello, World!")

योग्य output देत असेल, तर basic environment काम करत असल्याची पहिली confirmation मिळते.


Program breakdown#

PYTHON
print("Hello, World!")

याला parts मध्ये पाहू:

TEXT
print

Python built-in function.

TEXT
(

function call ची opening parenthesis.

TEXT
"Hello, World!"

display करायचा text.

TEXT
)

function call complete करते.

Output:

TEXT
Hello, World!

Code आणि Output वेगळे आहेत#

Beginner ची common confusion:

PYTHON
print("Hello")

हा source code आहे.

तर:

TEXT
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.

उदाहरण:

PYTHON
print("Welcome")

ही एक statement आहे.

आणखी एक:

PYTHON
print("Learning Python")

ही दुसरी statement आहे.

Program:

PYTHON
print("Welcome")
print("Learning Python")
print("Let's begin")

यामध्ये तीन statements आहेत.

Python सामान्यतः program top-to-bottom execute करते.

Execution flow:

TEXT
Statement 1
    ↓
Statement 2
    ↓
Statement 3

या program मध्ये:

PYTHON
print("Welcome")
print("Learning Python")
print("Let's begin")

execution:

TEXT
print("Welcome")
        ↓
print("Learning Python")
        ↓
print("Let's begin")

Output:

TEXT
Welcome
Learning Python
Let's begin

Statement order matters#

Compare करा:

Program A#

PYTHON
print("Login successful")
print("Welcome to dashboard")

Output:

TEXT
Login successful
Welcome to dashboard

Program B#

PYTHON
print("Welcome to dashboard")
print("Login successful")

Output:

TEXT
Welcome to dashboard
Login successful

दोन्ही programs technically valid आहेत.

पण statements चा order बदलल्यामुळे output order बदलला.

यातून एक fundamental principle समजतो:

Program म्हणजे फक्त instructions चा collection नाही; त्या instructions कोणत्या क्रमाने execute होतात हे देखील महत्त्वाचे असते.

प्रत्येक line म्हणजे नेहमी statement असते का?#

नाही.

उदाहरण:

PYTHON
# 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 # ने सुरू करता येतो.

PYTHON
# Display a welcome message
print("Welcome")

Output:

TEXT
Welcome

Comment output मध्ये दिसत नाही.


Comments का वापरायचे?#

Imagine करा तुम्ही आज code लिहिला:

PYTHON
print("Order received")
print("Payment pending")

आज तुम्हाला logic माहिती आहे.

पण सहा महिन्यांनंतर किंवा दुसऱ्या developer ने हा code पाहिला तर context लगेच समजेलच असे नाही.

Useful comment:

PYTHON
# Display the current order status
print("Order received")
print("Payment pending")

Comment code चा purpose समजण्यास मदत करतो.


Comment वापरून line temporarily ignore करणे#

PYTHON
print("Application started")

# print("Debug mode enabled")

print("Application ready")

Output:

TEXT
Application started
Application ready

दुसरे print() comment केले असल्यामुळे execute होत नाही.

याला अनेकदा commenting out code असे म्हणतात.


Good Comment vs Weak Comment#

Weak#

PYTHON
# Print welcome
print("Welcome")

Comment code जे स्पष्टपणे सांगतो तेच repeat करतो.

Better#

PYTHON
# 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 नंतरही # वापरता येतो.

PYTHON
print("Course Active")  # Status shown to enrolled learners

हे valid आहे.

परंतु प्रत्येक line वर inline comments टाकणे आवश्यक नाही.

Readable code ला unnecessary comments ने भरू नका.


Important clarification: # string मध्ये असेल तर?#

PYTHON
print("#Python")

Output:

TEXT
#Python

इथे #Python quotation marks मध्ये आहे.

म्हणून तो output चा भाग आहे; comment नाही.

Compare:

PYTHON
# 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 कडे पाहा:

PYTHON
print("Hello")

print() line च्या अगदी सुरुवातीपासून सुरू होते.

आता:

PYTHON
    print("Hello")

दुसऱ्या example मध्ये line च्या सुरुवातीला spaces आहेत.

हेच indentation.


Python मध्ये indentation का important आहे?#

काही programming languages blocks दाखवण्यासाठी { } वापरतात.

Python अनेक compound structures मध्ये indentation वापरते.

उदाहरण फक्त concept समजण्यासाठी:

PYTHON
if True:
    print("Inside block")

print("Outside block")

Output:

TEXT
Inside block
Outside block

आपण if statement या chapter मध्ये detail मध्ये शिकत नाही. येथे फक्त indentation चे काम समजण्यासाठी example आहे.

Observe:

PYTHON
if True:
    print("Inside block")

Indented line if च्या block चा भाग आहे.

तर:

PYTHON
print("Outside block")

ही त्या block च्या बाहेर आहे.


Visual understanding#

TEXT
if True:
│
└──    print("Inside block")
       ↑
       Indented → belongs to the block

print("Outside block")
↑
Not indented → outside the block

Incorrect indentation#

PYTHON
if True:
print("Hello")

Python ला block कुठे आहे हे valid syntax प्रमाणे सांगितले गेलेले नाही.

Typical result:

TEXT
IndentationError

यावेळी exact message context आणि Python version नुसार अधिक detail देऊ शकतो, त्यामुळे error चे wording memorize करण्याऐवजी कारण समजून घ्या.

Root Cause: block सुरू केल्यानंतर required statement indented केलेली नाही.

Correct version:

PYTHON
if True:
    print("Hello")

Inconsistent indentation#

Conceptually wrong formatting:

PYTHON
if True:
    print("First")
      print("Second")

दोन्ही statements एकाच logical block मध्ये असतील तर त्यांची indentation consistent असणे आवश्यक आहे.

Correct:

PYTHON
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 अशी असू शकते:

PYTHON
# Program purpose

print("Application started")
print("Processing request")
print("Application completed")

Conceptual structure:

TEXT
Optional useful comments
        ↓
Executable statements
        ↓
Statements arranged in logical order

Example: Student Registration Message#

Requirement:

User ला registration process चे stages display करायचे आहेत.

PYTHON
# Display registration process status

print("Student Registration")
print("Validating details")
print("Registration successful")

Output:

TEXT
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 बनवत आहोत:

PYTHON
print("Starting payment process")
print("Checking payment request")
print("Payment process completed")

Output:

TEXT
Starting payment process
Checking payment request
Payment process completed

Actual production applications मध्ये sophisticated logging systems वापरले जाऊ शकतात. पण logging हा या chapter च्या scope बाहेर आहे.

सध्या महत्त्वाचे learning:

TEXT
Program starts
    ↓
Statement executes
    ↓
Output appears
    ↓
Next statement executes

Realistic Mini Program#

Requirement:

एका online course application मध्ये learner ला basic enrollment progress दाखवायचा आहे.

PYTHON
# Course enrollment status

print("Course: Python Beginner")
print("Enrollment request received")
print("Enrollment successful")
print("You can start learning now")

Output:

TEXT
Course: Python Beginner
Enrollment request received
Enrollment successful
You can start learning now

आपण काय वापरले?#

  • # → comment
  • print() → 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:

PYTHON
print

Expected function call:

PYTHON
print("Hello")

Root Cause#

Function चे नाव आणि function call यातील फरक न समजणे.

Prevention#

print() वापरताना parentheses आवश्यक आहेत.


Mistake 2 — Text quotation marks शिवाय लिहिणे#

Incorrect:

PYTHON
print(Hello)

Beginner ला वाटू शकते की Python screen वर Hello print करेल.

पण Python quotation marks नसलेल्या Hello कडे plain text म्हणून पाहत नाही.

Correct:

PYTHON
print("Hello")

या chapter मध्ये variables शिकत नसल्यामुळे यापुढील internal meaning येथे expand करत नाही.


Mistake 3 — Output मध्ये quotation marks दिसतील असे समजणे#

Code:

PYTHON
print("Python")

Output:

TEXT
Python

Not:

TEXT
"Python"

Quotation marks source code मध्ये text delimit करण्यासाठी आहेत.


Mistake 4 — Comment execute होईल असे समजणे#

PYTHON
# print("Hello")

यामुळे output येत नाही.

कारण पूर्ण line comment झाली आहे.


Mistake 5 — # कुठेही दिसला म्हणजे comment#

PYTHON
print("#Python")

येथे #Python string content आहे.

Output:

TEXT
#Python

Mistake 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:

PYTHON
print("Start")
print("End")

याला random spaces देणे चांगली formatting नाही.

Indentation फक्त logical structure नुसार वापरा.


Misconception — प्रत्येक Python program ला fixed main() आवश्यक आहे#

Basic Python script लिहिण्यासाठी compulsory main() method आवश्यक नाही.

हा valid complete script आहे:

PYTHON
print("Hello")

Larger Python applications मध्ये developers वेगवेगळ्या structures वापरतात, पण त्या या introductory chapter च्या scope बाहेर आहेत.


4. Hands-On Practice#

Practice 1 — Course Welcome Program#

Requirement#

तीन lines display करा:

TEXT
Welcome to CodeLangs AI
Python Beginner Course
Learning Started

Learner Task#

स्वतः code लिहा.

Hint 1#

प्रत्येक output line साठी print() वापरू शकता.

Hint 2#

Text quotation marks मध्ये लिहा.

Solution#

PYTHON
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:

PYTHON
print("Order confirmed")
print("Preparing order")

Task#

Program चा purpose explain करणारा useful comment पहिल्या line च्या आधी लिहा.

Solution#

PYTHON
# Display order processing status
print("Order confirmed")
print("Preparing order")

Practice 3 — Predict the Output#

PYTHON
print("Step 1")
# print("Step 2")
print("Step 3")

तुमचा answer आधी ठरवा.

Solution#

TEXT
Step 1
Step 3

Step 2 असलेली line comment आहे.


Practice 4 — Fix the Problem#

PYTHON
if True:
print("Python")

if चे detailed behavior शिकण्याची गरज नाही.

Task फक्त indentation fix करणे आहे.

Solution#

PYTHON
if True:
    print("Python")

Practice 5 — Build a Small Program#

Requirement#

एका learner चा course-start screen तयार करा.

Output:

TEXT
Python Beginner Course
Chapter 1 completed
Starting First Python Program

Program च्या वर एक meaningful comment असावा.

Solution#

PYTHON
# 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?
PYTHON
print("Python")

Answer:

TEXT
Python

The 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:

PYTHON
print("Hello")

is source code, while:

TEXT
Hello

is 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?
PYTHON
# 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:

PYTHON
print("#Python")

produces:

TEXT
#Python

6. Quick Revision#

ConceptRemember
print()Displays values/messages
Hello WorldMinimal program often used to verify basic setup
StatementInstruction Python can execute
CommentHuman-readable source text normally ignored during execution
#Starts a single-line comment when used outside a string
IndentationHelps define Python code blocks
Recommended indentationCommonly 4 spaces per level
Execution orderBasic sequential statements run top-to-bottom
Source codeInstructions written by developer
OutputResult produced by running code

Essential Example#

PYTHON
# Display course information

print("Python Beginner Course")
print("First Python Program")

Output:

TEXT
Python Beginner Course
First Python Program

7. 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 दाखवायचा आहे:

TEXT
CodeLangs AI
Python Beginner Course
Course access verified
Learning session started

Constraints#

तुमच्या 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#

PYTHON
# Display course access and learning session status

print("CodeLangs AI")
print("Python Beginner Course")
print("Course access verified")
print("Learning session started")

Reasoning#

Program मध्ये:

  1. comment program चा purpose सांगते.
  2. प्रत्येक print() executable statement आहे.
  3. statements वरून खाली logical order मध्ये execute होतात.
  4. top-level statements असल्यामुळे unnecessary indentation नाही.
  5. output आणि source code स्पष्टपणे वेगळे आहेत.