Class 12 Full Syllabus Notes
Class 12 Full Syllabus Notes
NITIN PALIWAL
Page 2
ADVANTAGES OF PYTHON:
DISADVANTAGES OF PYTHON:
Advantages Disadvantages
1. Readability 1. Speed
NITIN PALIWAL
Page 3
Advantages Disadvantages
TOKENS
TOKENS
LITERALS
IDENTIFIERS
KEYWORDS
OPERATORS
Keyword Description
and Logical operator for conjunction (logical AND).
as Used to create an alias for a module or symbol.
assert Used for debugging to check if a condition is true.
break Terminates the loop prematurely.
class Declares a class in object-oriented programming.
continue Skips the rest of the loop's code and continues to the next iteration.
def Defines a function.
del Deletes an object or a part of an object.
elif Stands for "else if" and is used in conditional statements.
else Specifies a block of code to be executed if the condition is false.
except Catches exceptions during exception handling.
False Boolean value representing false.
finally Specifies a block of code to be executed, regardless of the try-except block.
for Used to iterate over a sequence (e.g., list, tuple, string).
from Used to import specific attributes or functions from a module.
global Declares a global variable.
if Conditional statement, executes code if a specified condition is true.
import Imports a module into the current program.
in Membership test, checks if a value exists in a sequence.
is Compares object identity.
lambda Creates an anonymous function (lambda function).
None Represents the absence of a value or a null value.
not Logical operator for negation (logical NOT).
or Logical operator for disjunction (logical OR).
pass Placeholder indicating no action to be taken.
raise Raises an exception.
return Exits a function and returns a value.
True Boolean value representing true.
try Defines a block of code to be tested for errors.
Creates a loop that executes a block of code as long as a specified
while condition is true.
Simplifies resource management (e.g., file handling) using a context
with manager.
Pauses the execution of a generator function and returns a value to the
yield caller.
NITIN PALIWAL
Page 5
IDENTIFIERS
Examples of Identifiers:
Valid:
my_variable
count_1
PI
_underscore
Name123
Invalid:
123abc (starts with a digit)
my-var (contains a hyphen)
if (using a Python keyword)
spaces not allowed
#hash_symbol (contains a special character)
LITERALS
Represents the
NONE absence of a value
LITERALS
Integers: 42, -10
Floats: 3.14, -0.5
NUMERIC Complex Numbers: 2 + 3j
Lists: [1, 2, 3]
LITERAL Tuples: (1, 2, 3)
Sets: {1, 2, 3}
COLLECTIONS Dictionaries: {'key': 'value'}
NITIN PALIWAL
Page 6
PUNCTUATIONS
OPERATORS
IDENTITY Check if two objects are the same. Example: is/ is not
NITIN PALIWAL
Page 7
DATA TYPES
NUMBER
1) Integer DICTIONARY
2) Float
3) Complex Number 1) Unordered collection of key-value pairs.
2) Defined by curly braces ({}) with key-value pairs.
3) Example: person = {'name': 'John', 'age': 25}
STRING
1) Sequences of characters. SET
2) Enclosed in single (' '), double
(" "), or triple quotes. 1) Unordered, mutable collection with unique
3) Example: text = "Hello, World!" elements.
2) Defined by curly braces ({}).
3) Example: unique numbers = {1, 2, 3}
BOOLEAN
1) Represents truth values: True or False.
2) Used for logical operations and TUPLE
conditions.
3) Example: is_true = True 1) Ordered, immutable collection.
2) Defined by parentheses (()).
3) Example: coordinates = (x, y)
LIST
1) Ordered, mutable collection.
2) Defined by square brackets ([]).
3) Example: numbers = [1, 2, 3]
NITIN PALIWAL
Page 8
CONDITIONAL STATEMENTS
If Statement:
INPUT:
INPUT:
OUTPUT:
NITIN PALIWAL
Page 9
If-Else Statement:
Executes one block of code if a condition is true and another if it's false.
INPUT:
INPUT:
OUTPUT:
OUTPUT:
NITIN PALIWAL
Page 10
If-Elif-Else Statement:
INPUT:
INPUT:
OUTPUT:
NITIN PALIWAL
Page 11
INPUT: OUTPUT:
INPUT: OUTPUT:
NITIN PALIWAL
Page 12
INPUT:
OUTPUT:
NITIN PALIWAL
Page 13
INPUT:
OUTPUT:
NITIN PALIWAL
Page 14
INPUT:
OUTPUT:
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
INTRODUCTION TO FILES
A file is a named location on a secondary storage media where data are permanently
stored for later access.
TYPES OF FILES:
Text File:
Binary File:
Opening a File:
To open a file in Python, use the open() function with the syntax file_object =
open(file_name, access_mode).
open() returns a file object (file handle) stored in file_object.
file_object has attributes like file.closed, file.mode, and file.name, providing
information about the file.
file_name should be the name of the file. If not in the current directory, specify
the complete path.
access_mode is optional, representing the mode of file access. Also called
the processing mode. (e.g., 'r' for reading, 'w' for writing, 'a' for appending).
Default mode is read ('r'), and files can be opened in binary mode ('b') for non-
textual data.
NITIN PALIWAL
Page 3
Closing a File:
After read/write operations, it's good practice to close the file using the close()
method (file_object.close()).
Python flushes unwritten data before closing.
If a file object is reassigned or control exits a program block, the file is
automatically closed.
Python supports opening files using the with clause, ensuring automatic file
closure.
Syntax: with open(file_name, access_mode) as file_object:
Provides simpler syntax and automatic closure even if an exception occurs or
user forgets to close the file.
NITIN PALIWAL
Page 4
Note:
Differences:
NITIN PALIWAL
Page 5
Ensure file is opened in "r", "r+", "w+", or "a+" mode before reading.
Three methods to read contents:
o read(): Reads specified number of bytes.
o readline(): Reads one complete line or specified number of bytes.
o readlines(): Reads all lines and returns as list of strings.
Syntax: file_object.read(n).
Returns specified number of bytes.
If no argument or negative number specified, reads entire file.
NITIN PALIWAL
Page 6
Additional Notes:
Sequential access is common, but Python offers seek() and tell() for random
access.
Note:
NITIN PALIWAL
Page 7
Seeking Adventure:
NITIN PALIWAL
Page 8
Introduction:
Python treats everything as objects, including data types like lists,
tuples, and dictionaries.
Sometimes, it's necessary to store the current state of variables for
later retrieval.
Pickle module helps serialize and deserialize Python objects, allowing
for easy storage and retrieval.
Program Examples:
Pickling Data:
Example: Writing a list to a binary file.
Method: pickle.dump(data_object, file_object).
Unpickling Data:
Example: Reading data from a binary file.
Method: stored_object = pickle.load(file_object).
Conclusion:
Pickle module offers a convenient way to store and retrieve Python
objects.
Serialization and deserialization simplify data handling tasks, ensuring
data persistence and ease of use.
NITIN PALIWAL
Page 9
CSV FILES
CSV is a plain-text format for storing tabular data, where each line represents
a row, and fields are separated by commas.
It is a widely used format for data interchange due to its simplicity and
compatibility with various applications.
Python provides the csv module for reading and writing CSV files.
csv.reader() function is used to read data from a CSV file.
Each row from the CSV file is returned as a list of strings.
EXAMPLE:
import csv
NITIN PALIWAL
Page 10
NCERT PROGRAMS:
NITIN PALIWAL
Page 11
NITIN PALIWAL
Page 12
NITIN PALIWAL
Page 13
NITIN PALIWAL
Page 14
NITIN PALIWAL
Page 15
COMMON QUESTIONS
1. Opening a file: r+ mode opens the file if it exists, while w+ mode also
opens the file, but it deletes all the content present in the file. The pointer
in both cases is present at the start of the file.
2. Making a new file: If the file does not exist, r+ throws an exception error
of 'filenotfound' while w+ creates a new empty file. No error message is
thrown in w+ mode.
4. Writing a file: r+ overwrites the file with the new content from the
beginning of the document, while w+ deletes all the old content and then
adds the new text to the file.
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
Computer Networks:
Benefits of Interconnectivity:
EVOLUTION OF NETWORKING
NITIN PALIWAL
Page 3
TYPES OF NETWORKS
NITIN PALIWAL
Page 4
NITIN PALIWAL
Page 5
NETWORK DEVICES
1. Modem:
Mounts on computer's
motherboard.
3. RJ45 Connector:
NITIN PALIWAL
Page 6
4. Repeater:
5. Hub:
6. Switch:
7. Router:
NITIN PALIWAL
Page 7
8. Gateway:
NETWORK TOPOLOGIES
1. Bus Topology:
NITIN PALIWAL
Page 8
2. Star Topology:
NITIN PALIWAL
Page 9
NETWORK PROTOCOLS
8. Telnet:
NITIN PALIWAL
Page 10
WEB SERVICES
4. Domain Names:
6. Website:
7. Web Browser:
8. Web Servers:
9. Web Hosting:
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
DATA COMMUNICATION:
Concept:
Bandwidth:
NITIN PALIWAL
Page 3
SWITCHING TECHNIQUES
Switching Overview:
In a network with multiple devices, establishing one-to-one
communication is vital.
Dedicated connections for each device pair (mesh or star topology) are
costly for large networks.
Switching offers an alternative by routing data through various network
nodes.
Circuit Switching:
Definition: Establishes a dedicated path between sender and receiver
before communication.
Process: Identifies a connected sequence of links between network
nodes.
Example: Traditional telephone calls where a physical path is
established from sender to receiver.
Characteristic: All packets follow the same path set during connection.
NITIN PALIWAL
Page 4
Packet Switching:
Definition: Breaks down information into smaller packets for
transmission.
Process: Packets are transmitted independently through the network.
Route Flexibility: Packets may take different routes depending on
network conditions.
Packet Structure: Each packet comprises a header with destination
address and main message part.
Reassembly: At the destination, packets are reassembled to retrieve
the complete message.
Channel Usage: Channels are occupied only during packet
transmission, freeing up for other communication afterwards.
TRANSMISSION MEDIA
NITIN PALIWAL
Page 5
Guided Transmission:
Unguided Transmission:
NITIN PALIWAL
Page 6
Coaxial Cable:
Structure: Features a copper core surrounded by insulating
material and an outer conductor (usually copper mesh).
Characteristics: Offers better shielding and higher bandwidth
compared to twisted pair cables.
Applications: Suitable for transmitting signals of higher
frequencies over longer distances.
Optical Fiber:
Structure: Utilizes thin glass fibers to carry data as light signals.
Advantages: Lightweight, immune to electromagnetic
interference, capable of high-speed data transmission over long
distances.
Applications: Widely used in backbone networks for high-
performance data transmission.
NITIN PALIWAL
Page 7
Wireless Technologies:
Bluetooth:
Description: Short-range wireless technology operating at the
2.4 GHz frequency band.
Applications: Enables wireless connections between devices
within close proximity, forming personal area networks
(piconets).
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
DATA STRUCTURE
A data structure defines a mechanism to store, organise and access data along with
operations (processing) that can be efficiently performed on the data.
STACK
Introduction to Stack
Analogous to piles of books or plates at home.
New items are added to and removed from the top of the pile.
Conventional to add/remove objects only from the top due to
convenience.
This linear order of arrangement is termed as a stack.
APPLICATIONS OF STACK
Real-Life Applications
Piles of clothes in an almirah.
Vertical stacks of chairs.
Bangles worn on the wrist.
Piles of boxes of eatables in a pantry or kitchen shelf.
Programming Applications
String Reversal: Easily achieved by placing characters of a
string in a stack and retrieving them in reverse order.
Text/Image Editing: Stack keeps track of changes made,
enabling redo/undo functionalities in text/image editors.
Web Browsing: Back button functionality in browsers is
implemented using a stack to maintain the history of visited web
pages.
Arithmetic Expressions: Used to handle matching of
parentheses in arithmetic expressions, ensuring proper nesting
and throwing errors for mismatched parentheses.
NITIN PALIWAL
Page 3
OPERATIONS ON STACK
Stack Fundamentals
Stack implements Last-In-First-Out (LIFO) arrangement.
Elements are added to and deleted from one end, termed as the TOP
of the stack.
Key Operations
PUSH: Adds a new element at the top of the stack.
Insertion operation.
Continues until the stack is full, resulting in an 'overflow'
exception if attempted beyond capacity.
POP: Removes the topmost element of the stack.
Deletion operation.
Continues until the stack is empty, resulting in an 'underflow'
exception if attempted on an empty stack.
IMPLEMENTATION OF STACK
NITIN PALIWAL
Page 4
NITIN PALIWAL
Page 5
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
DATABASE CONCEPTS:
Definition of a File:
Container for storing data on a computer system.
Contents can vary from text to multimedia files.
Example Continuation:
Separate storage of student and attendance data in two files.
Description of columns in both STUDENT and ATTENDANCE files.
Difficulty in Access:
Files require application programs for data retrieval.
Challenges arise due to unforeseen data access requirements.
Data Redundancy:
Duplicated data in different files leads to redundancy.
Example: Repeated student names and guardian details.
Data Inconsistency:
Mismatch of data in different files due to lack of synchronization.
Changes in one file may not reflect in another, causing inconsistencies.
Data Isolation:
Lack of linkage between related files necessitates separate programs
for access.
Complex systems with disparate file formats pose challenges in data
retrieval.
Data Dependence:
Changes in file structure require modifications in all accessing
programs.
Failure to update programs leads to operational issues.
NITIN PALIWAL
Page 3
Features of DBMS:
Applications of Databases:
Banking: Customer information, account details, transactions, etc.
Crop Loan: Farmer data, land details, loan history, etc.
Inventory Management, Organizational Resource Management, Online
Shopping.
NITIN PALIWAL
Page 4
Types of DBMS:
Classification based on underlying data models.
Data model defines database structure, relationships, and constraints.
Most commonly used: Relational Data Model.
Limitations of DBMS:
Increased complexity in maintenance and operational functionalities.
Vulnerability to data loss due to hardware or software failures.
NITIN PALIWAL
Page 5
Types of Keys:
Candidate Key:
Attributes with distinct values capable of uniquely identifying tuples.
Candidates for becoming the primary key.
Example: GUID and GPhone in the GUARDIAN relation.
Primary Key:
Chosen attribute, among candidate keys, to uniquely identify tuples.
Remaining candidate keys termed as alternate keys.
Example: GUID chosen as the primary key in the GUARDIAN relation.
Composite Primary Key:
Multiple attributes together form the primary key when no single
attribute is sufficient.
Called composite primary key.
Example: {RollNumber, AttendanceDate} in the ATTENDANCE
relation.
Foreign Key:
Represents relationships between two relations.
Derived from the primary key of another relation.
Attribute in referencing relation becomes a foreign key.
Allows referencing contents from another relation.
Can take NULL if not part of the primary key of the foreign table.
Example shown in the schema diagram of the Student Attendance
database.
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
FUNCTIONS
WHAT ARE FUNCTIONS?
A function is a reusable block of code that performs a specific task or set of tasks.
Functions provide a way to organize code into modular and manageable pieces.
They take input, process it, and produce output. Functions are crucial for promoting
code reusability, readability, and maintainability.
TYPES OF FUNCTIONS:
Built-in Functions:
Definition: Functions that are predefined in Python and come built into the
interpreter.
Examples:
len(): Returns the length of an object (e.g., a string, list, or tuple).
print(): Outputs text or variables to the console.
type(): Returns the type of an object.
User-Defined Functions:
Definition: Functions created by the user to perform specific tasks or
operations.
Example:
NITIN PALIWAL
Page 3
FUNCTION BASICS
PARAMETER
ARGUMENT
Default Parameters:
Definition: Assign default values to parameters in the function definition.
If an argument is not provided during the function call, the default value is
used.
DEFAULT PARAMETER
Positional Parameters:
Definition: Parameters defined by their position in the function call.
The order and number of arguments matter.
NITIN PALIWAL
Page 4
# Calculate total canvas area used for making the tent 4. Cost Calculation:
- The program prompts the
canvas_area = csa_conical + csa_cylindrical
user to enter the cost of 1 m² of
print("The area of the canvas is", canvas_area, "m^2") canvas.
- It calculates the total cost of
canvas by multiplying the total
# Prompting the user to enter the cost of 1 m^2 canvas
canvas area by the unit price.
unit_price = float(input("Enter the cost of 1 m^2 canvas: "))
5. Tax Calculation and Net
Amount Payable:
# Calculate total cost of canvas
- Tax is calculated as 18% of
total_cost = unit_price * canvas_area the total cost.
print("The total cost of canvas = ", total_cost) - The net amount payable by
the customer, including tax, is
calculated by adding the tax to
# Adding tax to the total cost to calculate net amount payable by the
the total cost.
customer
tax = 0.18 * total_cost 6. Output:
- The program displays the
net_price = total_cost + tax
area of the canvas, total cost of
print("Net amount payable = ", net_price) canvas, and the net amount
payable by the customer.
NITIN PALIWAL
Page 5
csa_cyl = cyl(h, r) # Function call to calculate cylindrical area - Total canvas area and cost
l = float(input("Enter slant height of the conical area in meters: ")) are calculated based on user
inputs.
csa_con = con(l, r) # Function call to calculate conical area
# Calculate area of the canvas used for making the tent 5. Tax Calculation and Net
canvas_area = csa_cyl + csa_con Amount Payable:
NITIN PALIWAL
Page 6
# Function call
addnum() # Call the function to execute
PASSED AS AN ARGUMENT.
sum = sum + i
print("The sum of first", n, "natural numbers is:", sum)
# Function call
sumSquares(num)
NITIN PALIWAL
Page 8
NITIN PALIWAL
Page 9
NITIN PALIWAL
Page 1
NITIN PALIWAL
Page 2
Versatility: Despite being called a query language, SQL can perform various
tasks beyond querying. It provides statements for defining data structure, data
manipulation, declaring constraints, and retrieving data in different ways
based on requirements..
Definition: Data type indicates the type of data value an attribute can have
and determines the operations that can be performed on it.
Examples: MySQL supports numeric types, date and time types, and string
types.
Commonly Used Data Types:
CHAR(n): Fixed-length character type data with length n (0 to 255).
Padded with spaces if needed.
VARCHAR(n): Variable-length character type data with maximum length
n (0 to 65535). Adjusts storage based on actual string length.
INT: Integer value occupying 4 bytes, supporting unsigned values up to
4,294,967,295. For larger values, use BIGINT (8 bytes).
FLOAT: Decimal numbers, each value occupying 4 bytes.
DATE: Date type in 'YYYY-MM-DD' format, supporting a range from
'1000-01-01' to '9999-12-31'..
CONSTRAINTS
NITIN PALIWAL
Page 3
CREATE Database
Definition: To store data, we need to create a database and its tables
(relations) using the CREATE DATABASE statement.
Syntax: CREATE DATABASE databasename;
Example: CREATE DATABASE StudentAttendance;
Activity:
Objective: Check if the database 'StudentAttendance' was created
successfully.
Command: show databases;
Observation: The 'StudentAttendance' database should be listed.
CREATE Table:
Definition: After creating a database, we define relations (tables) within it
using the CREATE TABLE statement.
Describe Table
Purpose: View the structure of an existing table using the DESCRIBE
statement.
Syntax: DESCRIBE tablename;
ALTER Table
Definition: Modify the structure of an existing table using the ALTER
statement.
Actions: Add/remove attributes, modify datatypes, add constraints, etc.
Syntax: Various ALTER TABLE statements for different modifications.
A. Adding Columns:
Syntax: ALTER TABLE table_name ADD column_name datatype;
Example: ALTER TABLE Students ADD Email VARCHAR(50);
B. Modifying Columns:
Syntax: ALTER TABLE table_name MODIFY column_name new_datatype;
Example: ALTER TABLE Students MODIFY Email VARCHAR(100);
NITIN PALIWAL
Page 4
C. Renaming Columns:
Syntax: ALTER TABLE table_name RENAME COLUMN old_column TO
new_column;
Example: ALTER TABLE Students RENAME COLUMN Email TO Email_Address;
D. Dropping Columns:
Syntax: ALTER TABLE table_name DROP COLUMN column_name;
Example: ALTER TABLE Students DROP COLUMN Email_Address;
E. Adding Constraints:
Syntax: ALTER TABLE table_name ADD CONSTRAINT constraint_name
constraint_definition;
Example: ALTER TABLE Students ADD CONSTRAINT pk_student_id PRIMARY
KEY (StudentID);
F. Dropping Constraints:
Syntax: ALTER TABLE table_name DROP CONSTRAINT constraint_name;
Example: ALTER TABLE Students DROP CONSTRAINT pk_student_id;
G. Adding Indexes:
Syntax: ALTER TABLE table_name ADD INDEX index_name (column_name);
Example: ALTER TABLE Students ADD INDEX idx_student_name (Name);
H. Dropping Indexes:
Syntax: ALTER TABLE table_name DROP INDEX index_name;
Example: ALTER TABLE Students DROP INDEX idx_student_name;
DROP Statement:
Purpose: Permanently remove a table or database from the system.
Syntax:
o To drop a table: DROP TABLE table_name;
o To drop a database: DROP DATABASE database_name;
NITIN PALIWAL
Page 5
Inserting Records
To add new data into a table, we use the INSERT INTO statement. Here's the
syntax:
DELETE Command:
Syntax: DELETE FROM table_name WHERE condition;
Example: DELETE FROM EMPLOYEE WHERE Salary < 20000;
SELECT Statement:
Syntax: SELECT column1, column2, ... FROM table_name WHERE
condition;
Example: SELECT EName, Salary FROM EMPLOYEE WHERE DeptId =
'D01';
NITIN PALIWAL
Page 6
Logical Operators:
Syntax: AND, OR, NOT
Example: SELECT * FROM EMPLOYEE WHERE DeptId = 'D01' AND
Salary > 40000;
Aliasing:
Syntax: SELECT column_name AS alias_name FROM table_name;
Example: SELECT Salary AS MonthlySalary FROM EMPLOYEE;
DISTINCT Clause:
Syntax: SELECT DISTINCT column_name FROM table_name;
Example: SELECT DISTINCT DeptId FROM EMPLOYEE;
WHERE Clause:
Syntax: SELECT * FROM table_name WHERE condition;
Example: SELECT * FROM EMPLOYEE WHERE Salary > 50000;
IN Operator:
Syntax: SELECT * FROM table_name WHERE column_name IN
(value1, value2, ...);
Example: SELECT * FROM EMPLOYEE WHERE DeptId IN ('D01',
'D02', 'D03');
BETWEEN Operator:
Syntax: SELECT * FROM table_name WHERE column_name BETWEEN
value1 AND value2;
Example: SELECT * FROM EMPLOYEE WHERE Salary BETWEEN 30000
AND 60000;
ORDER BY Clause:
Syntax: SELECT * FROM table_name ORDER BY column_name [ASC |
DESC];
Example: SELECT * FROM EMPLOYEE ORDER BY Salary DESC;
Meaning of NULL:
Represents missing or unknown values.
IS NULL Operator:
Syntax: SELECT * FROM table_name WHERE column_name IS NULL;
Example: SELECT * FROM EMPLOYEE WHERE Bonus IS NULL;
LIKE Operator:
Syntax: SELECT * FROM table_name WHERE column_name LIKE
pattern;
Example: SELECT * FROM EMPLOYEE WHERE EName LIKE 'A%';
NITIN PALIWAL
Page 7
UPDATE Command:
Syntax: UPDATE table_name SET column1 = value1, column2 =
value2, ... WHERE condition;
Example: UPDATE EMPLOYEE SET Salary = 55000 WHERE EName =
'Kritika';
GROUP BY Clause:
Syntax: SELECT column1, function(column2) FROM table_name
GROUP BY column1;
Example: SELECT DeptId, AVG(Salary) FROM EMPLOYEE GROUP BY
DeptId;
HAVING Clause:
Syntax: SELECT column1, function(column2) FROM table_name
GROUP BY column1 HAVING condition;
Example: SELECT DeptId, AVG(Salary) FROM EMPLOYEE GROUP BY
DeptId HAVING AVG(Salary) > 40000;
Joins:
Cartesian Product: No explicit syntax, it's a result of not specifying a
JOIN condition.
Equi-Join: SELECT * FROM table1 JOIN table2 ON table1.column =
table2.column;
Natural Join: SELECT * FROM table1 NATURAL JOIN table2;
NITIN PALIWAL
Page 8
NITIN PALIWAL
Page 9
NITIN PALIWAL