Pyth 11th Rev
Pyth 11th Rev
Let's now begin a complete and structured revision of Chapter 1: Python Basics (Class
11 revision) — which is essential for your Class 12 Computer Science foundation.
1. What is Python?
Python is a high-level, interpreted, general-purpose programming language known for its
readability and simplicity.
2. Python Keywords
Examples: if, else, for, while, def, True, False, return, and, or, etc.
3. Identifiers
print(type(a))
# Output
print("Hello", name)
6. Operators
Type Example
Arithmetic +, -, *, /, %, **
Assignment =, +=, -=
Comparison ==, !=, <, >
Logical and, or, not
Membership in, not in
Identity is, is not
7. Control Statements
If-Else Statement
x=5
if x > 0:
print("Positive")
else:
print("Non-positive")
Elif Statement
n = int(input("Enter number: "))
if n > 0:
print("Positive")
elif n == 0:
print("Zero")
else:
print("Negative")
8. Loops
For Loop (with range)
for i in range(1, 6):
print(i)
While Loop
x=1
while x <= 5:
print(x)
x += 1
9. Strings Basics
s = "Python"
print(s[0]) #P
print(s[-1]) #n
print(s[1:4]) # yth
print(len(s)) #6
String Methods:
s.lower(), s.upper(), s.isalpha(), s.isdigit(), s.replace("P", "J")
lst.append(40)
lst.remove(20)
print(lst[1]) # 30
print(len(lst)) #3
Output: 20
Because multiplication happens before addition.
Output: yth
Summary Cheat-Sheet
print() Output
Shall I now remind you to start the flashcard quiz on File Handling, Functions, and Python
Basics?