Python Programming Notes (English + Simple Hindi)

Complete study material – click a topic below to jump to its notes

Topics of Python Programming

1. Introduction to Python / पाइथन का परिचय

English

What is Python? Python is a high-level, interpreted, general-purpose programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability with its notable use of significant indentation. Python supports multiple programming paradigms, including procedural, object-oriented, and functional programming.

Key Features:

  • Simple and easy to learn – ideal for beginners
  • Interpreted – no compilation step, run code directly
  • Dynamically typed – no need to declare variable types
  • Large standard library and huge ecosystem of third-party packages
  • Cross-platform: Windows, macOS, Linux

Basic Structure of a Python Program: Python programs are just text files with a .py extension. They are executed line by line by the Python interpreter.

सरल हिंदी

पाइथन क्या है? पाइथन एक उच्च-स्तरीय, इंटरप्रेटेड, सामान्य प्रयोग वाली प्रोग्रामिंग भाषा है। इसे 1991 में गुइडो वैन रोसुम ने बनाया था। यह कोड को पढ़ने में आसान बनाने के लिए इंडेंटेशन (खाली स्थान) का उपयोग करती है।

मुख्य विशेषताएँ:

  • सीखना बहुत आसान – शुरुआती के लिए एकदम सही।
  • इंटरप्रेटेड – बिना कंपाइल किए सीधे कोड चलाया जा सकता है।
  • डायनामिक टाइपिंग – वेरिएबल का टाइप बताने की जरूरत नहीं।
  • विशाल मानक पुस्तकालय (standard library) और बाहरी पैकेज।
  • क्रॉस-प्लेटफॉर्म – विंडोज, मैक, लिनक्स सब पर काम करती है।

पाइथन प्रोग्राम की संरचना: पाइथन प्रोग्राम .py फाइल में लिखे जाते हैं। इंटरप्रेटर इसे लाइन-दर-लाइन चलाता है।

# My first Python program
print("Hello, World!")

Explanation: Python doesn't need a main function; execution starts from the first line. print() is a built-in function that outputs text. Comments start with #.

व्याख्या: पाइथन में main() की जरूरत नहीं होती; प्रोग्राम पहली लाइन से शुरू होता है। print() एक बिल्ट-इन फंक्शन है जो टेक्स्ट प्रिंट करता है। कमेंट # से शुरू होते हैं।

↑ Back to Top

2. Basic Syntax / मूल वाक्यविन्यास

English

Key syntax rules:

  • Indentation: Python uses indentation (spaces or tabs) to define blocks of code. Consistent indentation is mandatory.
  • Comments: Single-line comments start with #. Multi-line strings can be used as comments but are not technically comments.
  • Statements: Usually one per line; no semicolon needed (but you can use them to separate multiple statements on one line).
  • Case sensitivity: Python is case‑sensitive (name and Name are different).

Identifiers (names): Must start with a letter or underscore, followed by letters, digits, or underscores. Cannot use keywords (like if, for, while).

सरल हिंदी

महत्वपूर्ण सिंटैक्स नियम:

  • इंडेंटेशन: पाइथन में ब्लॉक दिखाने के लिए इंडेंटेशन (स्पेस या टैब) का इस्तेमाल होता है। पूरे ब्लॉक में एक समान इंडेंटेशन होना जरूरी है।
  • कमेंट्स: एक लाइन के कमेंट के लिए # का इस्तेमाल करते हैं।
  • स्टेटमेंट्स: आमतौर पर एक लाइन में एक स्टेटमेंट; सेमीकोलन की जरूरत नहीं है।
  • केस सेंसिटिव: पाइथन छोटे-बड़े अक्षरों में फर्क करती है। age और Age अलग-अलग हैं।

आइडेंटिफायर (नाम): नाम अक्षर या अंडरस्कोर से शुरू होना चाहिए, उसके बाद अक्षर, अंक या अंडरस्कोर हो सकते हैं। कीवर्ड (जैसे if, else) का इस्तेमाल नाम के रूप में नहीं कर सकते।

# Program to show syntax
age = 25          # variable assignment
if age >= 18:     # colon indicates start of block
    print("Adult")   # indented block
    print("You can vote")
print("Always executed")  # outside block

Explanation: Notice the colon : after the if condition, and the consistent indentation (4 spaces) inside the if block.

व्याख्या: if के बाद कोलन : और ब्लॉक के अंदर एक समान इंडेंटेशन (4 स्पेस) का ध्यान दें।

↑ Back to Top

3. Data Types / डेटा प्रकार

English

Python has several built-in data types. The main ones are:

  • Numeric: int (integers), float (decimals), complex.
  • Sequence: str (string), list, tuple, range.
  • Mapping: dict (dictionary).
  • Set: set, frozenset.
  • Boolean: bool (True / False).
  • None: NoneType (represents absence of value).

Python is dynamically typed – you don't need to declare the type; it is inferred at runtime.

सरल हिंदी

पाइथन में कई बिल्ट-इन डेटा टाइप होते हैं। मुख्य इस प्रकार हैं:

  • न्यूमेरिक: int (पूर्णांक – 10, -3), float (दशमलव – 3.14, -0.5), complex (जटिल संख्या)।
  • सीक्वेंस: str (स्ट्रिंग – टेक्स्ट), list (सूची), tuple (टपल), range (श्रेणी)।
  • मैपिंग: dict (डिक्शनरी – की-वैल्यू जोड़े)।
  • सेट: set, frozenset (अद्वितीय तत्वों का संग्रह)।
  • बूलियन: bool (True / False – सही/गलत)।
  • None: NoneType (जब कुछ भी वैल्यू न हो)।

पाइथन डायनामिकली टाइप्ड है – वेरिएबल का टाइप पहले से बताने की जरूरत नहीं; वह रनटाइम पर अपने आप समझ लिया जाता है।

# Data type examples
x = 10              # int
y = 3.14            # float
name = "HITCOM"     # str
is_active = True    # bool
colors = ["red","green","blue"]  # list
coordinates = (10,20)            # tuple
person = {"name":"Alice","age":25} # dict

print(type(x))      # <class 'int'>
print(type(colors)) # <class 'list'>

Explanation: Use type() to check the data type of a variable.

व्याख्या: type() फंक्शन से किसी वेरिएबल का डेटा टाइप देख सकते हैं।

↑ Back to Top

4. Variables & Constants / चर और स्थिरांक

English

Variables: In Python, variables are created the moment you assign a value. No explicit declaration needed. Variable names are case‑sensitive and must follow identifier rules.

Constants: Python doesn't have true constants, but by convention, names in ALL_CAPS are treated as constants (should not be changed).

Multiple assignment: You can assign values to multiple variables in one line.

सरल हिंदी

वेरिएबल: पाइथन में जैसे ही आप किसी नाम को वैल्यू देते हैं, वह वेरिएबल बन जाता है। पहले से डिक्लेयर करने की जरूरत नहीं। नाम केस-सेंसिटिव होते हैं।

कॉन्स्टैंट्स: पाइथन में स्थिरांक (जिन्हें बदलना न हो) के लिए कोई विशेष नियम नहीं, लेकिन परंपरा अनुसार नाम को पूरे बड़े अक्षरों में लिखते हैं (जैसे PI = 3.14) और उसे बदलने से बचते हैं।

एक साथ कई वेरिएबल असाइन करना: x, y, z = 10, 20, 30 – इस तरह एक लाइन में कई वेरिएबल को वैल्यू दे सकते हैं।

# Variables
student_name = "Raj"
age = 21
age = 22        # reassign

# Multiple assignment
x, y, z = 10, 20, 30

# Constant convention
PI = 3.14159
MAX_SIZE = 100
↑ Back to Top

5. Input & Output / इनपुट और आउटपुट

English

Output: print() prints values to the console. You can print multiple items separated by commas.

Input: input(prompt) reads a line from the user, always returns a string. Convert to other types using int(), float(), etc.

सरल हिंदी

आउटपुट: print() का इस्तेमाल स्क्रीन पर कुछ छापने के लिए करते हैं। एक से ज्यादा चीजें कॉमा से अलग करके छाप सकते हैं।

इनपुट: input() यूजर से इनपुट लेता है। यह हमेशा एक स्ट्रिंग (टेक्स्ट) लौटाता है। अगर नंबर चाहिए तो int() या float() से बदलना पड़ता है।

name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Hello", name, "you are", age, "years old.")
↑ Back to Top

6. Operators / ऑपरेटर

English

Python supports various operators:

  • Arithmetic: +, -, *, /, // (floor division), % (modulo), ** (power)
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: and, or, not
  • Assignment: =, +=, -=, *=, /=, //=, %=, **=
  • Membership: in, not in
  • Identity: is, is not
  • Bitwise: &, |, ^, ~, <<, >>

सरल हिंदी

पाइथन में कई प्रकार के ऑपरेटर होते हैं:

  • अरिथमेटिक (गणित): +, -, *, /, // (पूर्ण भाग), % (शेष), ** (घातांक)
  • तुलना (comparison): == (बराबर), != (बराबर नहीं), <, >, <=, >=
  • तार्किक (logical): and (और), or (या), not (नहीं)
  • असाइनमेंट: =, +=, -=, *=, /=, आदि
  • मेंबरशिप: in (अंदर है), not in (अंदर नहीं है)
  • आइडेंटिटी: is, is not (दो वेरिएबल एक ही ऑब्जेक्ट हैं या नहीं)
a, b = 15, 4
print(a + b)   # 19
print(a / b)   # 3.75
print(a // b)  # 3  (floor division)
print(a ** b)  # 50625  (15^4)

# Logical
print(a > 10 and b < 5)   # True

# Membership
fruits = ["apple", "banana"]
print("apple" in fruits)   # True
↑ Back to Top

7. Control Structures (if-elif-else) / नियंत्रण संरचनाएँ

English

if, elif, else: Python uses if, elif (else if), and else for decision making. Blocks are defined by indentation.

सरल हिंदी

if, elif, else: निर्णय लेने के लिए। अगर शर्त सही है तो एक ब्लॉक चलता है, नहीं तो दूसरा। elif का इस्तेमाल कई शर्तों के लिए करते हैं। इंडेंटेशन से ब्लॉक बनते हैं।

num = int(input("Enter a number: "))
if num > 0:
    print("Positive")
elif num == 0:
    print("Zero")
else:
    print("Negative")
↑ Back to Top

8. Loops / लूप्स

English

while loop: Repeats while a condition is true.

for loop: Used to iterate over sequences (list, string, range, etc.).

break exits loop; continue skips to next iteration.

सरल हिंदी

while लूप: जब तक शर्त सही है, ब्लॉक को बार-बार चलाता है।

for लूप: किसी सूची, स्ट्रिंग या रेंज के सभी आइटम पर एक-एक करके चलता है।

break लूप को तुरंत खत्म कर देता है; continue मौजूदा इटरेशन छोड़कर अगले पर चला जाता है।

# while
i = 1
while i <= 5:
    print(i)
    i += 1

# for
for i in range(1,6):
    print(i)

fruits = ["apple","banana","cherry"]
for f in fruits:
    print(f)
↑ Back to Top

9. Strings / स्ट्रिंग्स

English

Strings are sequences of characters, immutable. Many built-in methods: len(), upper(), lower(), strip(), split(), join(), find(), etc.

सरल हिंदी

स्ट्रिंग अक्षरों का क्रम होती है। इसे बदला नहीं जा सकता (immutable)। कई उपयोगी मेथड्स हैं: len() – लंबाई, upper() – बड़े अक्षर, lower() – छोटे अक्षर, strip() – आगे-पीछे के स्पेस हटाना, split() – टुकड़ों में बाँटना, join() – जोड़ना, find() – ढूँढ़ना।

s = "  Hello, Python!  "
print(s.strip())        # remove spaces
print(s.lower())
print(s.replace("Python","World"))
words = s.split(",")    # split into list
print(words)
↑ Back to Top

10. Lists / सूचियाँ

English

Lists are ordered, mutable collections. Can hold mixed types. Common methods: append(), insert(), remove(), pop(), sort(), reverse(), slicing.

सरल हिंदी

लिस्ट एक क्रमबद्ध सूची होती है जिसे बदला जा सकता है (mutable)। इसमें किसी भी टाइप के आइटम रख सकते हैं। मुख्य मेथड: append() – अंत में जोड़ना, insert() – बीच में डालना, remove() – हटाना, pop() – अंतिम हटाना, sort() – क्रम में लगाना, reverse() – उल्टा करना। स्लाइसिंग [start:end] से हिस्सा निकाल सकते हैं।

nums = [10,20,30,40]
nums.append(50)
nums.insert(2,25)
print(nums[1:4])   # slicing
nums.sort()
print(nums)
↑ Back to Top

11. Tuples / टपल

English

Tuples are ordered, immutable sequences. Useful for fixed data. Defined with parentheses.

सरल हिंदी

टपल भी लिस्ट की तरह होता है, लेकिन इसे बदला नहीं जा सकता (immutable)। इसे () में लिखते हैं। यह उन आइटम्स के लिए उपयोगी है जो नहीं बदलने वाले हों।

point = (10,20)
print(point[0])
# point[0] = 5  # Error, immutable
↑ Back to Top

12. Dictionaries / शब्दकोश

English

Dictionaries store key-value pairs. Mutable. Keys must be immutable (strings, numbers, tuples).

सरल हिंदी

डिक्शनरी में की (key) और वैल्यू (value) के जोड़े होते हैं। की के जरिए वैल्यू ढूँढ़ी जाती है। डिक्शनरी को बदला जा सकता है। की हमेशा अपरिवर्तनशील (immutable) होनी चाहिए, जैसे स्ट्रिंग, नंबर, या टपल।

student = {"name":"Anjali", "age":22, "course":"B.Tech"}
print(student["name"])
student["grade"] = "A"
for key,val in student.items():
    print(key, val)
↑ Back to Top

13. Sets / सेट

English

Sets are unordered collections of unique elements. Support mathematical operations like union, intersection, difference.

सरल हिंदी

सेट अद्वितीय (unique) तत्वों का अनियंत्रित (unordered) संग्रह है। इसमें एक ही मान दो बार नहीं हो सकता। गणित के सेट ऑपरेशन जैसे union (मिलान), intersection (समान) आदि कर सकते हैं।

s1 = {1,2,3,3,4}
print(s1)   # {1,2,3,4}
s2 = {3,4,5}
print(s1 | s2)  # union -> {1,2,3,4,5}
print(s1 & s2)  # intersection -> {3,4}
↑ Back to Top

14. Functions / फंक्शन

English

Functions are defined with def. They can take parameters and return values. Python supports default arguments, keyword arguments, and variable-length arguments (*args, **kwargs).

सरल हिंदी

फंक्शन को def कीवर्ड से बनाते हैं। यह पैरामीटर ले सकता है और वैल्यू लौटा सकता है। डिफॉल्ट पैरामीटर भी दे सकते हैं। return से वैल्यू लौटाते हैं।

def add(a,b):
    return a + b

def greet(name="Guest"):
    print(f"Hello, {name}!")

result = add(5,3)
print(result)
greet("Amit")
↑ Back to Top

15. File Handling / फ़ाइल हैंडलिंग

English

Use open() to open a file. Modes: 'r' read, 'w' write (overwrite), 'a' append, 'r+' read/write. Always close the file or use with block for automatic closing.

सरल हिंदी

open() से फ़ाइल खोलते हैं। मोड: 'r' पढ़ने के लिए, 'w' लिखने के लिए (पुराना डेटा मिट जाता है), 'a' जोड़ने के लिए। फ़ाइल को बंद करना जरूरी है, with ब्लॉक अपने आप बंद कर देता है।

# Writing
with open("sample.txt","w") as f:
    f.write("Hello, file!\nSecond line")

# Reading
with open("sample.txt","r") as f:
    content = f.read()
    print(content)

# Append
with open("sample.txt","a") as f:
    f.write("\nAppended line")
↑ Back to Top