LearningPython TutorialIntroduction & Setup
CHAPTER 1 · PYTHON BASICS

Python Introduction & Setup

Python ek beginner-friendly, general-purpose programming language hai. Is first chapter me hum Python kya hai, Python 3 kaise use hota hai, first program kaise run hota hai, scripts aur interactive mode ka difference, comments, indentation ka basic idea aur BrounStack online runner se practice samjhenge.

English + Hinglish40 min readOnline practice included

What is Python?

Python is a high-level, general-purpose programming language known for readable syntax and a large ecosystem. It is used for automation, web backends, data work, scripting, testing, education, machine learning and many other kinds of software.

Hinglish Explanation

Python ka syntax relatively clean hota hai, isliye beginner logic par focus kar sakta hai instead of unnecessary boilerplate par. Lekin simple syntax ka matlab ye nahi ki Python sirf beginners ke liye hai — professional systems me bhi extensively use hota hai.

Why learn Python?

  • Readable syntax se programming fundamentals samajhna easier hota hai.
  • Automation scripts quickly likhe ja sakte hain.
  • Web, data, AI, testing aur tooling ke liye mature libraries available hain.
  • Cross-platform hai: Windows, macOS aur Linux par use kiya ja sakta hai.
  • Large community aur documentation ecosystem available hai.
Important: Har problem ke liye Python best choice nahi hoti. Language choice performance, platform, team, deployment aur project requirements par depend karti hai.

Use Python 3

Modern learning aur new projects ke liye Python 3 use karo. Python 2 obsolete hai and should not be chosen for new beginner work.

version-checkTerminal
python --version
# or on some systems
python3 --version

Exact command operating system aur installation setup par depend kar sakta hai.

BrounStack online Python runner

Is course ke examples practice karne ke liye local installation immediately required nahi hai. BrounStack Code Playground me Python code edit aur run kar sakte ho.

Runner note: Python server execution protected hai, isliye BrounStack sign-in required ho sakta hai. HTML/CSS/JavaScript playground browser me directly run hota hai.

Open Python Playground →

Your first Python program

hello.pyPython
print("Hello, BrounStack!")

print() console par text output karta hai.

Try it Yourself →

How Python code runs

Beginner level par tum Python ko an interpreter-driven language samajh sakte ho: source code Python runtime ko diya jata hai aur runtime instructions execute karta hai. CPython internally source ko bytecode me compile karke virtual machine par execute karta hai, so “interpreted vs compiled” ko absolute binary rule samajhna accurate nahi hai.

Simple flow

your_code.py → Python runtime → execution → output/error. Abhi internal bytecode details yaad karne ki zarurat nahi; important ye hai ki code ko Python runtime execute karta hai.

Python script file

Python source files commonly .py extension use karti hain.

greeting.pyPython
name = "Broun"
print("Welcome,", name)

A local script can commonly be run with:

terminalCommand
python greeting.py

Try it Yourself →

Interactive mode vs script

Python can also be used interactively in a REPL (Read-Eval-Print Loop), where you type an expression and immediately see its result.

interactivePython
>>> 2 + 3
5
>>> "BrounStack".upper()
'BROUNSTACK'
  • REPL: quick experiments and small checks.
  • Script: repeatable programs saved in files.
  • Playground: browser-based practice without local editor setup.

Comments

A comment explains code for humans and is not executed as a normal statement.

comments.pyPython
# This is a comment
print("Python practice")  # inline comment
Good comment: Why explain karo when reason is not obvious. Har simple line ko restate karne wale comments avoid karo.

Indentation matters

Python me indentation sirf visual formatting nahi hai. It defines code blocks.

indentation.pyPython
age = 20

if age >= 18:
    print("Adult")

print("Program finished")

if statement ko Chapter 6 me detail me padhenge. Abhi sirf observe karo ki indented line condition ke block ke andar hai.

Beginner rule: Spaces/tabs randomly mix mat karo. Most Python style uses 4 spaces per indentation level.

Python is case-sensitive

case.pyPython
course = "Python"
Course = "Different variable"

print(course)
print(Course)

course and Course are different names.

A first input() preview

input() user se text read kar sakta hai. Input/output ko Chapter 5 me detail me cover karenge.

hello-user.pyPython
name = input("Your name: ")
print("Hello,", name)

Try with stdin →

Errors are normal

Programming me errors learning process ka normal part hain. Python usually error type, message and line information show karta hai.

broken.pyPython
print("Hello"

This has invalid syntax because the closing parenthesis is missing. Error ko hide karne ke bajay message read karo and failing line inspect karo.

Local setup overview

Online runner se course start ho sakta hai, but later local Python install karna useful hoga for files, packages, virtual environments and larger projects.

  1. Python 3 official distribution ya trusted package manager se install karo.
  2. Terminal me version command verify karo.
  3. Code editor choose karo.
  4. .py file create karo.
  5. Terminal se script run karo.
Do not rush: Agar local setup issue ho, course ko playground ke through continue kar sakte ho. Later setup troubleshoot karenge.

Beginner best practices

  • Python 3 use karo.
  • Code small examples me test karo.
  • Error message ko read karo before random changes.
  • Consistent indentation maintain karo.
  • Meaningful names use karo.
  • Concept ko copy-paste se zyada edit karke test karo.
  • Har example ka output predict karo, phir run karo.

Common beginner mistakes

  • Print() likhna instead of print().
  • Quotes ya parentheses close karna bhoolna.
  • Indentation mismatch karna.
  • Python 2 tutorial follow karna.
  • File ko .py extension ke bina save karna.
  • Error message padhe bina code baar-baar change karna.
  • REPL prompt symbols >>> ko script file me copy kar dena.

Chapter checklist

  • Python ka general purpose samajh aaya?
  • Python 3 aur Python 2 ka basic difference clear hai?
  • print() se first output bana sakte ho?
  • .py script idea samajh aaya?
  • REPL vs script ka difference clear hai?
  • Comments aur indentation ka basic role samajh aaya?
  • BrounStack Python Playground me example open kar sakte ho?
  • Syntax error aane par message inspect karne ka habit clear hai?

Practice Task — First Python Session

BrounStack Playground ya local Python me ye tasks complete karo.

  1. Hello, BrounStack! print karo.
  2. Apna naam ek variable me rakhkar print karo.
  3. Do numbers ka sum print karo.
  4. Ek comment add karo explaining what program does.
  5. Text ko uppercase method ke saath experiment karo.
  6. input() se naam lo and greeting print karo.
  7. Intentional missing parenthesis error create karo and error message read karo.
  8. course and Course naam use karke case sensitivity observe karo.
  9. Ek tiny if example copy karke indentation change karke error/behavior observe karo.
  10. Finally clean working version save karo.