Python Coding – Basics & Syntax
Hinglish Quick Reference | NIELIT M3-R5 ke liye useful
1. Python Kya Hai
Python ek high-level, easy-to-read programming language hai. C/C++ ki tarah curly braces { } aur
semicolon (;) ki zaroorat nahi hoti — Python indentation (spacing) se code blocks define karta hai.
• File extension: .py
• Python interpreted language hai — line by line execute hoti hai.
• Case-sensitive hai: Name aur name alag variables maane jaate hain.
• Comments # se shuru hote hain (single line).
2. Indentation – Sabse Important Concept
Python me code block (jaise if, for, function ke andar ka code) indentation (spaces/tab) se define hota
hai, curly braces se nahi. Galat indentation se IndentationError aata hai.
if 5 > 2:
print("5 is greater") # indented — if ke andar
print("Outside if") # indent nahi — bahar
3. Data Types (Variables)
Data Type Example Meaning
int x = 10 whole number
float x = 3.14 decimal number
str x = "Ravi" text / string
bool x = True True / False
list x = [1,2,3] changeable, ordered collection
tuple x = (1,2,3) unchangeable, ordered collection
dict x = {"a":1} key-value pairs
Note: Python me variable declare karte waqt data type batane ki zaroorat nahi — Python khud detect kar leta hai
(dynamic typing).
4. Operators
Type Symbols Example
Arithmetic + - * / % // ** a // b (floor div), a ** b (power)
Comparison == != < > <= >= if x == 10:
Logical and or not if a > 5 and b < 10:
Assignment = += -= *= /= x += 1 (same as x = x+1)
5. Input aur Output
name = input("Enter your name: ") # user se input leta hai (string)
age = int(input("Enter age: ")) # int() se number me convert
print("Hello", name) # output print karta hai
print(f"Age is {age}") # f-string formatting
6. Control Structures
6.1 if / elif / else
if x > 10:
print("Big")
elif x == 10:
print("Equal")
else:
print("Small")
6.2 for loop
for i in range(5): # 0,1,2,3,4 — 5 baar chalega
print(i)
for item in [1,2,3]: # list ke har element pe chalega
print(item)
6.3 while loop
i = 0
while i < 5:
print(i)
i += 1 # increment zaroori, warna infinite loop
7. Functions
def greet(name): # 'def' se function banate hain
return "Hello " + name
result = greet("Ravi")
print(result) # Output: Hello Ravi
• Function define karne ke liye def keyword use hota hai.
• return statement value wapas bhejta hai; ismein na likhein to function None return karta hai.
• Function ke parameters me default value bhi de sakte hain: def greet(name="Guest"):
8. String & List Operations (Common)
Operation Example Result
Length len("hello") 5
Slicing "hello"[1:4] 'ell'
Concatenation "a" + "b" 'ab'
List append [Link](5) adds 5 at end
List length len([1,2,3]) 3
Split string "a,b".split(",") ['a', 'b']
9. Comments
# Ye single line comment hai
'''
Ye multi-line comment/
docstring hai
'''
10. Example Program — Even/Odd Checker
Ek simple program jo number even hai ya odd, ye check karta hai.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(num, "is Even")
else:
print(num, "is Odd")
Note: Exam me 'indentation ka role', 'for vs while ka difference', aur 'list vs tuple' jaise concepts frequently puche
jaate hain.
11. Exam Quick Facts (One-Liners)
• Python dynamically typed language hai — variable ka type run-time pe decide hota hai.
• Indentation Python me zaroori hai, ye curly braces { } ki jagah leta hai.
• List mutable (changeable) hoti hai, Tuple immutable (unchangeable) hoti hai.
• Python me semicolon (;) optional hai, zaroori nahi.
• range(5) 0 se 4 tak numbers deta hai (5 exclude).
• len() function kisi bhi string/list/tuple ki length batata hai.
• input() hamesha string return karta hai, chahe number hi kyu na ho.
• Comment ke liye # (single line) aur '''...''' (multi-line) use hota hai.
Prepared for exam revision — NIELIT M3-R5 Python basics.