Type Example Python Code
Text "Hello" x = "Hello"
Number 7, 3.14 x = 7, x = 3.14
Boolean True / False x = True
Python functions
1 input-------print
num = input("Enter any number: ")
print("You entered", num)
🔹 1. if – else condition (जैसे decision लेना)
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are not an adult.")
3. Multiple Conditions – elif
python
CopyEdit
marks = int(input("Enter your marks: "))
if marks >= 90:
print("Grade: A")
elif marks >= 75:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
else:
print("Grade: Fail")
oprators
Symbol Meaning Example
== Equal x == y
!= Not equal x != y
> Greater than x>y
< Less than x<y
Greater or
>= x >= y
equal
<= Less or equal x <= y
🔹 4. Even or Odd Checker
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
Loop banana prattern banann
Ke liyr for function
n = 2
for i in range(1, 11):
print(n, "x", i, "=", n * i)
for i in range(1, 6):
print("*" * i) prattern aata h *,**,***,*****,*****
🔍 Step-by-Step Explanation:
🔹i = 1
• Ek variable i banaya jisme value 1 rakhi
🔹 while i <= 5:
• Jab tak i ki value 5 se chhoti ya barabar hai, tab tak loop chalega
• Jaise hi i > 5 ho jayega, loop band ho jayega
🔹 print(i)
• Har baar current value of i ko screen par print karega
🔹i = i + 1
• Ye line i ki value ko 1 se badha deta hai
• Isse loop next number par chala jata hai
fruits = ["apple", "banana", "mango", "orange"]
print(fruits)
Add (append): [Link]("grapes") print(fruits)
Remove: [Link]("banana")
Len function
Len function me [6,3,5,2,4,9,8,7,1]me length nikal te h ye averege nikal ne me kam aata h
ex –y= [6,3,5,2,4,9,8,7,1]ki length9 ki h
len(y)
Range function:
Jab hum loop me value lete h tab
For i in renge (3) tab iska matlab 0,1,2 hoga
Matrix me bi 3x3 ki matrix me bi 0,1,2 row
0,1,2 colum hote h
[1, 2, 3], [4, 5, 6], [7, 8, 9] iss Matrix me anti digonal ki position kya hogi?
matrix[i][2 - i] ye ans h
2—i means 2-0,2-1,2-2
Metrix method
int("abc") # Error
int("12a") # Error int function====intiger ke liye use kare
int("10") # OK