CBSE Computer Science (083)
Class XI & XII – Most Important Functions, Methods and Commands for Board Exams
Exam-Oriented Quick Reference
This chapter is designed as a revision handbook for CBSE Computer Science Code 083.
It covers:
Python built-in functions
String methods
List methods
Tuple functions/methods
Dictionary functions/methods
Set functions/methods commonly useful in Python
mathmodulerandommodulestatisticsmoduleUser-defined functions
File-handling functions and methods
Binary-file methods
CSV-file functions
Exception-handling keywords
Stack-related list methods
Python–MySQL connectivity methods
Important SQL functions
Important differences frequently tested in examinations
Output-based examples
Board-exam traps and common mistakes
PART A – PYTHON BUILT-IN FUNCTIONS
These functions are available directly in Python. Usually, no module needs to be imported for them.
1. print()
Purpose
Displays output on the screen.
Syntax
print(value)
Example
print("Hello")
print(10)
print(5 + 3)
Output
Hello
10
8
2. input()
Purpose
Takes input from the user.
Important Board Rule
input() returns a string by default.
name = input("Enter name: ")
For numbers:
age = int(input("Enter age: "))
marks = float(input("Enter marks: "))
Very Important
x = input()
If the user enters:
25
then:
type(x)
is:
str
3. len()
Purpose
Returns the number of items/characters.
String
len("Computer")
Output:
8
List
len([10, 20, 30])
Output:
3
Dictionary
len({"A": 10, "B": 20})
Output:
2
4. type()
Purpose
Returns the data type of an object.
x = 25
print(type(x))
Output:
<class 'int'>
Examples:
type(10) # int
type(10.5) # float
type("Hello") # str
type([1,2,3]) # list
type((1,2,3)) # tuple
type({"a":1}) # dict
5. id()
Purpose
Returns the identity of an object.
x = 10
print(id(x))
The exact number can vary between executions.
Exam Point
id() is different from:
==
and:
is
6. int()
Purpose
Converts a value to integer.
int("25")
Output:
25
int(12.8)
Output:
12
7. float()
Purpose
Converts a value to floating-point number.
float("25.5")
Output:
25.5
8. str()
Purpose
Converts a value into a string.
str(100)
Output:
'100'
Example:
age = 18
print("Age = " + str(age))
9. bool()
Purpose
Converts a value into Boolean value.
bool(1)
Output:
True
bool(0)
Output:
False
Important false-like values include:
False
0
0.0
""
[]
()
{}
None
10. abs()
Purpose
Returns absolute value.
abs(-25)
Output:
25
11. round()
Purpose
Rounds a number.
round(12.56)
Output:
13
round(12.3456, 2)
Output:
12.35
12. pow()
Purpose
Calculates power.
pow(2, 3)
Output:
8
Equivalent:
2 ** 3
13. min()
Purpose
Returns the smallest value.
min(10, 5, 20)
Output:
5
List:
min([10, 5, 20])
14. max()
Purpose
Returns the largest value.
max(10, 5, 20)
Output:
20
15. sum()
Purpose
Returns the sum of values.
sum([10, 20, 30])
Output:
60
16. sorted()
Purpose
Returns a new sorted list.
a = [30, 10, 20]
b = sorted(a)
print(b)
print(a)
Output:
[10, 20, 30]
[30, 10, 20]
Golden Rule
sorted()
does not change the original list.
17. list()
Converts an iterable into a list.
list("ABC")
Output:
['A', 'B', 'C']
18. tuple()
Converts an iterable into a tuple.
tuple([1, 2, 3])
Output:
(1, 2, 3)
19. dict()
Creates a dictionary.
d = dict(name="Raj", age=17)
print(d)
20. range()
Used mainly with loops.
range(5)
generates:
0 1 2 3 4
Examples:
range(1, 6)
generates:
1 2 3 4 5
range(10, 0, -1)
generates:
10 9 8 7 6 5 4 3 2 1
Syntax
range(start, stop, step)
The stop value is excluded.
PART B – STRING FUNCTIONS AND METHODS
Strings are immutable.
Example:
s = "Computer"
1. len()
len("Computer")
Result:
8
2. capitalize()
Converts the first character to uppercase and the remaining characters to lowercase.
"hello WORLD".capitalize()
Result:
Hello world
3. title()
Converts the first character of each word to uppercase.
"computer science".title()
Result:
Computer Science
4. lower()
Converts characters to lowercase.
"PYTHON".lower()
Result:
python
5. upper()
Converts characters to uppercase.
"python".upper()
Result:
PYTHON
6. count()
Counts occurrences.
"banana".count("a")
Result:
3
7. find()
Returns the first position of a substring.
"computer".find("put")
Result:
3
If not found:
"computer".find("xyz")
Result:
-1
Important
find() returns -1 when the substring is absent.
8. index()
Returns the position of a substring.
"computer".index("put")
Result:
3
If the substring does not exist, index() raises an exception.
Important Difference
find() | index() |
|---|---|
| Returns position | Returns position |
If absent → -1 | If absent → error |
| Safer for checking existence | Raises exception if absent |
9. startswith()
Checks whether a string starts with specified text.
"Computer Science".startswith("Computer")
Result:
True
10. endswith()
Checks whether a string ends with specified text.
"Python.py".endswith(".py")
Result:
True
11. isalnum()
Checks whether all characters are alphabetic or numeric.
"ABC123".isalnum()
Result:
True
Space causes:
"ABC 123".isalnum()
to return:
False
12. isalpha()
Checks whether all characters are alphabets.
"Computer".isalpha()
Result:
True
13. isdigit()
Checks whether all characters are digits.
"12345".isdigit()
Result:
True
14. islower()
Checks whether all cased characters are lowercase.
"hello".islower()
Result:
True
15. isupper()
Checks whether all cased characters are uppercase.
"HELLO".isupper()
Result:
True
16. isspace()
Checks whether all characters are whitespace.
" ".isspace()
Result:
True
17. lstrip()
Removes whitespace from the left side.
" Hello".lstrip()
Result:
"Hello"
18. rstrip()
Removes whitespace from the right side.
"Hello ".rstrip()
19. strip()
Removes whitespace from both sides.
" Hello ".strip()
Result:
"Hello"
20. replace()
Replaces one substring with another.
"Hello World".replace("World", "Python")
Result:
Hello Python
21. split()
Splits a string into a list.
"a,b,c".split(",")
Result:
['a', 'b', 'c']
Example:
s = "I love Python"
print(s.split())
Result:
['I', 'love', 'Python']
22. join()
Joins elements into a string.
"-".join(["2026", "09", "22"])
Result:
2026-09-22
Golden Rule
split():
String → List
join():
List of strings → String
23. partition()
Divides a string into three parts:
before separator
separator
after separator
Example:
"abc:def".partition(":")
Result:
('abc', ':', 'def')
Difference
split()
returns a list.
partition()
returns a tuple of three parts.
STRING SLICING
s = "COMPUTER"
Index positions:
C O M P U T E R
0 1 2 3 4 5 6 7
Examples:
s[0]
Result:
C
s[1:5]
Result:
OMPU
s[:4]
Result:
COMP
s[4:]
Result:
UTER
s[::-1]
Result:
RETUPMOC
PART C – LIST FUNCTIONS AND METHODS
Lists are mutable.
L = [10, 20, 30]
1. len()
len([10, 20, 30])
Result:
3
2. list()
Creates/converts into a list.
list("ABC")
Result:
['A', 'B', 'C']
3. append()
Adds one item at the end.
L = [10, 20]
L.append(30)
print(L)
Result:
[10, 20, 30]
Important
L.append([40,50])
produces:
[10,20,30,[40,50]]
4. extend()
Adds all elements of another iterable.
L = [10,20]
L.extend([30,40])
Result:
[10,20,30,40]
Difference
append([30,40])
adds one item.
extend([30,40])
adds two items.
5. insert()
Inserts an item at a specified position.
L = [10,30]
L.insert(1,20)
Result:
[10,20,30]
Syntax:
list.insert(index, value)
6. count()
Counts occurrences.
[1,2,2,3,2].count(2)
Result:
3
7. index()
Returns the first position of an item.
[10,20,30].index(20)
Result:
1
8. remove()
Removes the first matching value.
L = [10,20,20,30]
L.remove(20)
Result:
[10,20,30]
Important
remove() works with value, not index.
9. pop()
Removes and returns an item.
L = [10,20,30]
x = L.pop()
x becomes:
30
The list becomes:
[10,20]
Specific index:
L.pop(0)
10. reverse()
Reverses the original list.
L = [1,2,3]
L.reverse()
Result:
[3,2,1]
11. sort()
Sorts the original list.
L = [30,10,20]
L.sort()
Result:
[10,20,30]
Descending:
L.sort(reverse=True)
12. sorted()
Returns a new sorted list.
L = [30,10,20]
newL = sorted(L)
Original:
[30,10,20]
New:
[10,20,30]
13. min()
min([10,5,20])
Result:
5
14. max()
max([10,5,20])
Result:
20
15. sum()
sum([10,20,30])
Result:
60
VERY IMPORTANT LIST DIFFERENCES
| Method | Meaning |
|---|---|
append(x) | Adds one item |
extend(x) | Adds multiple items |
insert(i,x) | Adds item at index |
remove(x) | Removes first matching value |
pop() | Removes and returns item |
reverse() | Reverses original list |
sort() | Sorts original list |
sorted() | Returns a new sorted list |
count(x) | Counts occurrences |
index(x) | Returns first position |
PART D – TUPLE FUNCTIONS AND METHODS
Tuples are immutable.
T = (10,20,30)
1. len()
len((10,20,30))
Result:
3
2. tuple()
Converts an iterable into tuple.
tuple([1,2,3])
Result:
(1,2,3)
3. count()
Counts an item.
(10,20,20,30).count(20)
Result:
2
4. index()
Returns the first index.
(10,20,30).index(20)
Result:
1
5. sorted()
Returns a list.
sorted((30,10,20))
Result:
[10,20,30]
Important
Although the input is a tuple, sorted() returns a list.
6. min()
min((20,10,30))
Result:
10
7. max()
max((20,10,30))
Result:
30
8. sum()
sum((10,20,30))
Result:
60
TUPLE ASSIGNMENT
a, b, c = (10, 20, 30)
Now:
a = 10
b = 20
c = 30
Very common examination concept:
a, b = b, a
This swaps two values.
PART E – DICTIONARY FUNCTIONS AND METHODS
Dictionary stores data in:
key : value
Example:
student = {
"name": "Raj",
"marks": 85
}
Dictionaries are mutable.
1. len()
Returns number of key-value pairs.
len({"a":10, "b":20})
Result:
2
2. dict()
Creates a dictionary.
d = dict(name="Raj", age=17)
3. keys()
Returns dictionary keys.
d = {"name":"Raj", "age":17}
print(d.keys())
4. values()
Returns values.
print(d.values())
5. items()
Returns key-value pairs.
print(d.items())
Typical output:
dict_items([('name', 'Raj'), ('age', 17)])
6. get()
Returns value associated with a key.
d.get("name")
Result:
Raj
It is safer than direct access when a key may not exist.
d.get("city")
returns:
None
unless a default value is supplied.
7. update()
Adds or modifies dictionary entries.
d = {"a":10}
d.update({"b":20})
Result:
{'a':10, 'b':20}
8. del
Removes a key-value pair.
d = {"a":10, "b":20}
del d["a"]
Result:
{'b':20}
del is a statement/keyword operation, not a dictionary method.
9. clear()
Removes all elements.
d.clear()
Result:
{}
10. fromkeys()
Creates a dictionary using specified keys.
dict.fromkeys(["a","b"], 0)
Result:
{'a':0, 'b':0}
11. copy()
Creates a shallow copy.
d2 = d.copy()
12. pop()
Removes a specified key and returns its value.
d = {"a":10, "b":20}
x = d.pop("a")
Now:
x = 10
d = {'b':20}
13. popitem()
Removes and returns the last inserted key-value pair.
d = {"a":10, "b":20}
x = d.popitem()
14. setdefault()
Returns the value of a key. If the key does not exist, it creates it.
d = {"a":10}
d.setdefault("b",20)
Result:
{'a':10, 'b':20}
15. max()
max({"a":10, "b":20})
For a dictionary, this works on the keys by default.
This is an important examination trap.
16. min()
Similarly, min(dictionary) works on keys.
17. sorted()
sorted(d)
returns a list containing sorted keys.
DICTIONARY TRAVERSAL
Keys
for k in d.keys():
print(k)
Values
for v in d.values():
print(v)
Both
for k, v in d.items():
print(k, v)
PART F – MATH MODULE
First:
import math
1. math.pi
Value of π.
math.pi
2. math.e
Euler's number.
math.e
3. math.sqrt()
Square root.
math.sqrt(25)
Result:
5.0
4. math.ceil()
Returns the smallest integer greater than or equal to the number.
math.ceil(5.2)
Result:
6
5. math.floor()
Returns the largest integer less than or equal to the number.
math.floor(5.9)
Result:
5
6. math.pow()
Power calculation.
math.pow(2,3)
Result:
8.0
7. math.fabs()
Returns absolute value as a floating-point number.
math.fabs(-10)
Result:
10.0
8. math.sin()
Sine of an angle in radians.
math.sin(0)
Result:
0.0
9. math.cos()
Cosine of an angle in radians.
math.cos(0)
Result:
1.0
10. math.tan()
Tangent of an angle in radians.
math.tan(0)
Result:
0.0
PART G – RANDOM MODULE
Import:
import random
1. random.random()
Returns a random floating-point number from:
0.0 <= value < 1.0
Example:
random.random()
2. random.randint(a,b)
Returns a random integer between a and b, including both endpoints.
random.randint(1,6)
Useful for dice simulation.
3. random.randrange()
Generates a random value from a range.
random.randrange(1,10)
Possible values:
1 to 9
because the stop value is excluded.
Difference
randint(1,10)
→ 1 through 10
randrange(1,10)
→ 1 through 9
PART H – STATISTICS MODULE
Import:
import statistics
1. statistics.mean()
Calculates arithmetic mean.
statistics.mean([10,20,30])
Result:
20
2. statistics.median()
Returns the middle value after ordering the data.
statistics.median([10,30,20])
Result:
20
3. statistics.mode()
Returns the most frequently occurring value.
statistics.mode([1,2,2,3])
Result:
2
For school-level programs, use data with a clear unique mode to avoid ambiguity.
PART I – USER-DEFINED FUNCTIONS
Class XII frequently tests the concept of user-defined functions.
Creating a function
def add(a, b):
return a + b
Calling:
print(add(10, 20))
Output:
30
Parameter vs Argument
def add(a, b):
return a + b
Here:
a and b = parameters
When:
add(10, 20)
then:
10 and 20 = arguments
Default Parameter
def greet(name="Student"):
print("Hello", name)
Calling:
greet()
Output:
Hello Student
Calling:
greet("Raj")
Output:
Hello Raj
Return Value
def square(n):
return n * n
x = square(5)
Now:
x = 25
Multiple Return Values
def calculate(a,b):
return a+b, a-b, a*b
Calling:
x, y, z = calculate(10,5)
Local Variable
A variable created inside a function normally has local scope.
def test():
x = 10
print(x)
Global Variable
A variable defined outside a function has global scope.
x = 100
def show():
print(x)
global
Used when a function needs to modify a global variable.
x = 10
def change():
global x
x = 20
PART J – FILE HANDLING METHODS
Class XII students must know these very well.
CBSE syllabus/practical material specifically includes text files, binary files, CSV files and file operations such as write(), writelines(), read(), readline(), readlines(), seek() and tell().
1. open()
Opens a file.
f = open("data.txt", "r")
Syntax:
open(filename, mode)
IMPORTANT FILE MODES
| Mode | Meaning |
|---|---|
r | Read |
w | Write; creates/overwrites |
a | Append |
r+ | Read + write |
w+ | Write + read; overwrites |
a+ | Append + read |
rb | Binary read |
wb | Binary write |
ab | Binary append |
Most Important Warning
w
can erase existing file contents.
2. close()
Closes a file.
f.close()
3. read()
Reads data from a text file.
f = open("data.txt", "r")
data = f.read()
print(data)
f.close()
4. read(n)
Reads approximately the specified number of characters.
f.read(10)
5. readline()
Reads one line.
line = f.readline()
6. readlines()
Reads all remaining lines and returns them as a list.
lines = f.readlines()
Example result:
['First line\n', 'Second line\n']
7. write()
Writes a string to a file.
f.write("Hello")
8. writelines()
Writes multiple strings.
f.writelines(["Hello\n", "Python\n"])
Important
writelines() does not automatically add newline characters.
Therefore:
f.writelines(["A\n", "B\n"])
is safer when separate lines are required.
9. tell()
Returns the current file pointer position.
f.tell()
10. seek()
Moves the file pointer.
f.seek(0)
moves the pointer to the beginning.
with STATEMENT
Recommended way to work with files:
with open("data.txt", "r") as f:
data = f.read()
print(data)
The file is automatically closed when the block finishes.
BINARY FILE FUNCTIONS
Binary files commonly use the pickle module.
import pickle
pickle.dump()
Writes an object to a binary file.
pickle.dump(data, f)
pickle.load()
Reads an object from a binary file.
data = pickle.load(f)
Common Binary File Pattern
import pickle
f = open("student.dat", "wb")
student = {
"roll": 101,
"name": "Raj"
}
pickle.dump(student, f)
f.close()
Reading:
f = open("student.dat", "rb")
data = pickle.load(f)
print(data)
f.close()
CSV FILE FUNCTIONS
CSV = Comma Separated Values.
Import:
import csv
csv.writer()
Creates a CSV writer object.
writer = csv.writer(f)
writerow()
Writes one row.
writer.writerow(["101", "Raj", "85"])
writerows()
Writes multiple rows.
writer.writerows([
["101","Raj",85],
["102","Amit",90]
])
csv.reader()
Reads CSV data.
reader = csv.reader(f)
for row in reader:
print(row)
PART K – EXCEPTION HANDLING
Important Class XII keywords:
try
except
else
finally
raise
Basic form:
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
try
Contains code that may generate an exception.
except
Handles the exception.
except ValueError:
print("Invalid value")
else
Executes when no exception occurs.
try:
x = int(input())
except ValueError:
print("Invalid")
else:
print("Valid number")
finally
Executes whether an exception occurs or not.
try:
print("Hello")
finally:
print("Always executed")
PART L – STACK USING LIST
CBSE Class XII commonly uses a Python list to implement a stack.
Stack follows:
LIFO
Last In First Out
PUSH
Use:
append()
Example:
stack = []
stack.append(10)
stack.append(20)
stack.append(30)
Stack:
30 ← TOP
20
10
POP
Use:
pop()
item = stack.pop()
The last item is removed.
Stack Test
if len(stack) == 0:
print("Stack Underflow")
or:
if not stack:
print("Stack Underflow")
PART M – PYTHON–MYSQL CONNECTIVITY
CBSE Computer Science material includes Python–SQL connectivity using methods such as connect(), cursor(), execute(), commit(), fetchone(), fetchall() and rowcount.
Typical import:
import mysql.connector
1. connect()
Creates a connection with MySQL.
con = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="school"
)
2. cursor()
Creates a cursor object.
cur = con.cursor()
3. execute()
Executes an SQL query.
cur.execute("SELECT * FROM student")
4. fetchone()
Fetches one record.
row = cur.fetchone()
5. fetchall()
Fetches all available records.
rows = cur.fetchall()
6. fetchmany()
Fetches a specified number of records.
rows = cur.fetchmany(5)
Use it when supported by the connector being taught.
7. commit()
Saves changes permanently.
Important for:
INSERT
UPDATE
DELETE
Example:
con.commit()
8. rollback()
Cancels uncommitted transaction changes.
con.rollback()
Useful when an operation fails before committing.
9. close()
Close cursor/connection.
cur.close()
con.close()
10. rowcount
Reports affected/fetched row count depending on the operation and connector.
print(cur.rowcount)
PART N – IMPORTANT SQL FUNCTIONS
For Class XII database questions, students should also revise commonly used SQL aggregate functions.
1. COUNT()
Counts rows/values.
SELECT COUNT(*) FROM Student;
2. SUM()
Calculates total.
SELECT SUM(Marks) FROM Student;
3. AVG()
Calculates average.
SELECT AVG(Marks) FROM Student;
4. MAX()
Returns maximum.
SELECT MAX(Marks) FROM Student;
5. MIN()
Returns minimum.
SELECT MIN(Marks) FROM Student;
Important SQL String Functions
Depending on the SQL functionality included in the prescribed course material, students commonly encounter functions such as:
UPPER()
LOWER()
LENGTH()
Example:
SELECT UPPER(Name) FROM Student;
PART O – MOST IMPORTANT DIFFERENCES FOR BOARD EXAMS
find() vs index()
find() | index() |
|---|---|
| Searches substring | Searches substring |
| Returns position | Returns position |
Not found → -1 | Not found → exception |
append() vs extend()
L.append([3,4])
gives:
[1,2,[3,4]]
while:
L.extend([3,4])
gives:
[1,2,3,4]
remove() vs pop()
L.remove(20)
removes by value.
L.pop(2)
removes by index and returns the removed item.
sort() vs sorted()
L.sort()
changes the original list.
sorted(L)
returns a new sorted list.
reverse() vs slicing
L.reverse()
changes the original list.
L[::-1]
returns a reversed copy/result.
split() vs partition()
"a-b-c".split("-")
Result:
['a', 'b', 'c']
"a-b-c".partition("-")
Result:
('a', '-', 'b-c')
read() vs readline() vs readlines()
| Method | Purpose |
|---|---|
read() | Reads complete/remaining content |
readline() | Reads one line |
readlines() | Reads lines and returns a list |
write() vs writelines()
| Method | Purpose |
|---|---|
write() | Writes one string |
writelines() | Writes multiple strings |
| Newline | Must generally be supplied explicitly |
randint() vs randrange()
random.randint(1,6)
Possible:
1,2,3,4,5,6
random.randrange(1,6)
Possible:
1,2,3,4,5
max() on a list vs dictionary
List:
max([10,30,20])
→ 30
Dictionary:
max({"a":10, "z":20})
works on keys by default.
PART P – MOST IMPORTANT is vs ==
==
Checks whether values are equal.
a = [1,2]
b = [1,2]
print(a == b)
Output:
True
is
Checks object identity.
a = [1,2]
b = [1,2]
print(a is b)
Normally:
False
because these are separate list objects.
Board Rule
Use:
==
for value comparison.
Use:
is
for identity comparison.
PART Q – None
None represents absence of a value.
Example:
x = None
Correct identity check:
if x is None:
print("No value")
PART R – IMPORTANT OUTPUT-BASED EXAMPLES
Example 1
s = "PYTHON"
print(s[1:4])
Answer:
YTH
Example 2
L = [10,20,30]
L.append(40)
print(L)
Answer:
[10, 20, 30, 40]
Example 3
L = [10,20,30]
print(L.pop())
Answer:
30
Example 4
d = {"a":10, "b":20}
print(d.get("c"))
Answer:
None
Example 5
print("computer".find("z"))
Answer:
-1
Example 6
print("ABC123".isalpha())
Answer:
False
Example 7
print("123".isdigit())
Answer:
True
Example 8
print(len("CBSE"))
Answer:
4
Example 9
print(sorted([30,10,20]))
Answer:
[10, 20, 30]
Example 10
L = [1,2,3]
print(L.reverse())
Answer:
None
The list itself becomes:
[3,2,1]
Very Important Board Trap
Methods such as:
append()
sort()
reverse()
generally modify the list and return None.
PART S – FUNCTIONS/METHODS STUDENTS SHOULD MEMORISE FIRST
Class XI Priority List
Basic functions
print()
input()
type()
len()
int()
float()
str()
bool()
abs()
round()
pow()
min()
max()
sum()
sorted()
list()
tuple()
dict()
range()
String
len()
capitalize()
title()
lower()
upper()
count()
find()
index()
startswith()
endswith()
isalnum()
isalpha()
isdigit()
islower()
isupper()
isspace()
lstrip()
rstrip()
strip()
replace()
split()
join()
partition()
List
len()
list()
append()
extend()
insert()
count()
index()
remove()
pop()
reverse()
sort()
sorted()
min()
max()
sum()
Tuple
len()
tuple()
count()
index()
sorted()
min()
max()
sum()
Dictionary
len()
dict()
keys()
values()
items()
get()
update()
clear()
fromkeys()
copy()
pop()
popitem()
setdefault()
sorted()
min()
max()
Modules
math.pi
math.e
math.sqrt()
math.ceil()
math.floor()
math.pow()
math.fabs()
math.sin()
math.cos()
math.tan()
random.random()
random.randint()
random.randrange()
statistics.mean()
statistics.median()
statistics.mode()
Class XII Priority List
Functions
def
return
global
File handling
open()
close()
read()
readline()
readlines()
write()
writelines()
seek()
tell()
Binary files
pickle.dump()
pickle.load()
CSV
csv.reader()
csv.writer()
writerow()
writerows()
Exception handling
try
except
else
finally
raise
Stack
append()
pop()
MySQL connectivity
connect()
cursor()
execute()
fetchone()
fetchall()
fetchmany()
commit()
rollback()
close()
rowcount
SQL aggregate functions
COUNT()
SUM()
AVG()
MAX()
MIN()
PART T – 30 MOST IMPORTANT ONE-LINE DEFINITIONS
len()– Returns the number of items/characters.type()– Returns the data type of an object.input()– Accepts input from the user as a string.print()– Displays output.range()– Generates a sequence of numbers.sorted()– Returns a new sorted list.append()– Adds one element to the end of a list.extend()– Adds multiple elements to a list.insert()– Inserts an element at a specified index.remove()– Removes the first matching value.pop()– Removes and returns an element.sort()– Sorts a list in place.reverse()– Reverses a list in place.find()– Returns the first position of a substring or-1.index()– Returns the position of an item/substring.split()– Divides a string into a list.join()– Combines strings using a separator.replace()– Replaces one substring with another.keys()– Returns dictionary keys.values()– Returns dictionary values.items()– Returns dictionary key-value pairs.get()– Retrieves the value associated with a dictionary key.update()– Adds or modifies dictionary entries.open()– Opens a file.read()– Reads file content.write()– Writes a string to a file.seek()– Moves the file pointer.tell()– Returns the current file-pointer position.execute()– Executes an SQL query through a database cursor.commit()– Permanently saves database transaction changes.
PART U – 20 GOLDEN RULES FOR BOARD EXAMS
Rule 1
input() returns a string.
Rule 2
Use int(input()) for integer input.
Rule 3
Strings are immutable.
Rule 4
Tuples are immutable.
Rule 5
Lists are mutable.
Rule 6
Dictionaries are mutable.
Rule 7
append() adds one item.
Rule 8
extend() adds elements individually.
Rule 9
remove() uses a value.
Rule 10
pop() uses an index and returns the removed item.
Rule 11
sort() changes the original list.
Rule 12
sorted() creates/returns a sorted list.
Rule 13
find() returns -1 if not found.
Rule 14
index() raises an exception if not found.
Rule 15
split() converts a string into a list.
Rule 16
join() combines strings.
Rule 17
== compares values.
Rule 18
is compares object identity.
Rule 19
w file mode can overwrite existing contents.
Rule 20
After INSERT, UPDATE or DELETE through Python–MySQL connectivity, remember:
con.commit()
FINAL SUPER-QUICK REVISION CHART
PYTHON
│
├── Basic
│ ├── print()
│ ├── input()
│ ├── type()
│ ├── len()
│ ├── int()
│ ├── float()
│ ├── str()
│ ├── bool()
│ ├── min()
│ ├── max()
│ ├── sum()
│ ├── sorted()
│ └── range()
│
├── STRING
│ ├── lower()
│ ├── upper()
│ ├── title()
│ ├── capitalize()
│ ├── count()
│ ├── find()
│ ├── index()
│ ├── replace()
│ ├── split()
│ ├── join()
│ ├── strip()
│ ├── startswith()
│ └── endswith()
│
├── LIST
│ ├── append()
│ ├── extend()
│ ├── insert()
│ ├── remove()
│ ├── pop()
│ ├── reverse()
│ └── sort()
│
├── TUPLE
│ ├── count()
│ ├── index()
│ ├── sorted()
│ ├── min()
│ ├── max()
│ └── sum()
│
├── DICTIONARY
│ ├── keys()
│ ├── values()
│ ├── items()
│ ├── get()
│ ├── update()
│ ├── pop()
│ ├── popitem()
│ ├── clear()
│ └── setdefault()
│
├── MODULES
│ ├── math
│ ├── random
│ └── statistics
│
├── FILES
│ ├── open()
│ ├── close()
│ ├── read()
│ ├── readline()
│ ├── readlines()
│ ├── write()
│ ├── writelines()
│ ├── seek()
│ └── tell()
│
├── BINARY
│ ├── pickle.dump()
│ └── pickle.load()
│
├── CSV
│ ├── csv.reader()
│ ├── csv.writer()
│ ├── writerow()
│ └── writerows()
│
└── MYSQL
├── connect()
├── cursor()
├── execute()
├── fetchone()
├── fetchall()
├── commit()
├── rollback()
├── close()
└── rowcount
10 Functions/Methods to Never Forget
If a student has very little revision time, first memorise these:
len()
range()
append()
pop()
sort()
sorted()
find()
split()
get()
items()
For Class XII additionally memorise:
open()
read()
readline()
readlines()
write()
writelines()
seek()
tell()
pickle.dump()
pickle.load()
csv.reader()
csv.writer()
connect()
cursor()
execute()
fetchone()
fetchall()
commit()
These form a particularly important practical and examination toolkit for Python, files, stacks, CSV and database connectivity in CBSE Computer Science.
RUonTop: Hi Welcome to our Blog...