BeSmart Computer Education Logo
BeSmart Computer Education Modern Computer Coaching in Haldwani
Call for Offline Batches

Python Chapter 1 — Introduction

BeSmart Computer Education — Haldwani • JSAN Media • contact@jsanmedia.com • +91 7533993929
Python Notes

Chapter 1 — Python Introduction & Basics

Medium: Hinglish (simple English + light Hindi). Goal: 12th-pass students ko solid foundation dena.

1) Python Kya & Kyun

What: Python ek high-level, interpreted language hai; readable syntax, huge libraries, beginners ke liye friendly.
Why: Web, data, AI/ML, scripting, automation — sab me use hoti hai; career scope wide & learning curve smooth.
Real-world: Instagram backend, YouTube recommendations, automation scripts, data analysis notebooks, etc.

2) Python kaise run hota hai (REPL vs Script)

What (REPL): Terminal me python likho → prompt >>> milta hai; 1-1 line test kar sakte ho.
What (Script): Code ko .py file me save karke python file.py run karte hain.
Why: REPL = quick experiments; Script = real programs, save/share/test.

3) Hello World + print()

print("Hello, BeSmart!")

Why: Console output seekhne ka first step; debugging ke liye helpful.

4) Comments & Docstrings

What: # se single-line comment; triple quotes """ ... """ for docstrings (functions/modules description).
Why: Code samajhne/maintain karne me help; documentation generate karne me useful.
# single-line comment
def greet(name):
    """Return a friendly greeting line."""
    return f"Hello, {name}!"

5) Indentation & Code Blocks

What: Python me braces {} nahi; indentation (spaces) se block banta hai.
Why: Readability aur structure consistent; indentation galat hoga to IndentationError.
x = 10
if x > 5:
    print("x is big")   # 4 spaces recommended

6) Variables & Naming Rules

What: Variable = named reference to a value. Python dynamically typed hai (type auto decide hota).
Why: Flexibility; fast prototyping.
Rules:
  • Start letter/underscore; a-z, A-Z, 0-9, _ allowed
  • No spaces; use snake_case (e.g., total_marks)
  • Keywords (e.g., for, class) not allowed
Examples:
name = "Aarav"
age = 17
is_student = True

7) Basic Data Types & Literals

What: int, float, bool, str, NoneType; containers (next chapters): list, tuple, dict, set.
Why: Correct type selection = fewer bugs, better memory/performance.
x = 10            # int
pi = 3.14         # float
flag = True       # bool
msg = "Hello"     # str
nothing = None    # NoneType

8) Type Conversion (Casting) & input()

What: int(), float(), str() se convert; input() hamesha string return karta hai.
Why: User input numbers me convert karke calculations possible hoti hain.
a = int(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Sum =", a + b)   # correct numeric addition

9) Operators (Arithmetic → Identity)

Arithmetic: + - * / // % **
Comparison: == != < > <= >=
Logical: and or not
Assignment: = += -=
Membership: in, not in
Identity: is, is not (same object?)
Tip: == value compare; is identity compare.
print(7 // 3)   # 2 (floor division)
print(2 ** 3)   # 8 (power)
print("py" in "python")  # True (membership)

10) Strings: Indexing, Slicing, Methods

What: String immutable hoti hai; indexes 0-based; slice [start:stop:step].
Why: Text handling me bahut common; slicing = fast extraction.
s = "BeSmart"
print(s[0], s[-1])    # 'B' 't'
print(s[0:2])         # 'Be'
print(s[::-1])        # 'tramSeB' (reverse)
print(s.lower(), s.upper(), s.count("e"))

11) Output Formatting (f-strings)

What: f-strings: f"Hello {name}". Alternatives: str.format(), old % formatting.
Why: Clean, readable interpolation; numbers ko format karna easy.
name, percent = "Riya", 92.456
print(f"{name} scored {percent:.1f}%")   # Riya scored 92.5%

12) Common Errors & Debug Basics

  • IndentationError: Spaces align nahi hue.
  • NameError: Variable define nahi.
  • TypeError: Incompatible types (e.g., "2" + 2).
  • ValueError: Wrong value (e.g., int("hello")).
Debug tip: Prints add karo, small parts me test karo, meaningful names use karo.

13) Mini Programs

A) Simple Calculator: Sum, Diff, Prod, Div

a = float(input("A: "))
b = float(input("B: "))
print("Sum:", a + b)
print("Diff:", a - b)
print("Prod:", a * b)
if b != 0:
    print("Div:", a / b)
else:
    print("Div: not allowed (b is 0)")

B) Temperature Converter (C → F)

c = float(input("Celsius: "))
f = (c * 9/5) + 32
print(f"{c:.1f}°C = {f:.1f}°F")

C) Percentage & Grade (very basic)

m1 = float(input("Marks 1: "))
m2 = float(input("Marks 2: "))
m3 = float(input("Marks 3: "))
percent = (m1 + m2 + m3) / 3
if percent >= 90: grade = "A+"
elif percent >= 75: grade = "A"
elif percent >= 60: grade = "B"
elif percent >= 40: grade = "C"
else: grade = "D"
print(f"Percent: {percent:.2f}% | Grade: {grade}")

14) Practice Questions

  1. Concept: Python “interpreted” hone ka kya matlab hai? REPL vs Script explain.
  2. Code: “Hello, <name>!” print karne ka program banao (user se name lo).
  3. Predict:
    x=5; y=2; print(x//y, x%y, x**y)
    Output explain.
  4. Strings: User se string lo; first, last, length print karo; reverse bhi print karo.
  5. Cast: input() se 2 numbers lekar unka average print karo (sahi casting karte hue).
  6. Format: f-string se pi=3.14159 ko 2 decimals me print karo.
  7. Identity: a = [1,2]; b = a; c = [1,2]a==b, a is b, a==c, a is c explain.
  8. Operators: Ek expression likho jo True aaye: not ((5 > 7) or ("py" not in "python")). Evaluate karke steps likho.
  9. Mini-task: Celsius ↔ Fahrenheit bi-directional converter banao (user unit choose kare).
  10. Debug: Niche code me error dhundo & fix karo:
    name = input("Name: ")
    print("Welcome " + name)
    age = int(input("Age: "))
    print("Next year you will be " + (age + 1))  # error?

15) Quick Cheatsheet

Basics:
  • print(), comments #, docstring """..."""
  • Indent = 4 spaces; blocks via colon : + indent
  • Types: int, float, bool, str, None
Common:
  • Cast: int(), float(), str()
  • Input: input()string
  • Format: f"{var:.2f}", {name=} (3.8+)

Leave a Comment