CS (083)
Class : XII (2025-
26)
Syllabus
Paper Pattern
STRINGS
Unicode
characters
ord() Enclosed in
single ,
str()
double or
chr() triple quotes
STRING
Store in
contiguous Immutable
memory
Occupies 1
byte
INDEXING
Forward
Indexing
0 1 2 3 4 5 6 7 8
E D U C A T I O N
Backwar
d -9 -8 -7 -6 -5 -4 -3 -2 -1
Indexing
TRAVERSIN
G
USING subscript AND range() USING in operator
SLICING
when no dimension is given :
SLICING
when only step is given :
SLICING
when index and step both are correct :
NOTE : when index is within range the stop-1 is considered else
whole string
SLICING
when index is correct but step is wrong :
SLICING
when index and step both are out of index :
SLICING
when start index is not given and stop index is out of bound:
SLICING
when stop index is not given and start index is out of bound:
STRING
Concatenation
OPERATOR
Replication
-> ‘+’ -> ‘*’
->Joins two strings -> It requires a string and a no.
only
Membership Comparision
-> in / not in -> == , != ,> , < ,>= ,<=
->Gives Boolean -> Works according to ASCII value
Results -> Gives Boolean result
BASIC STRING
FUNCTIONS
-> To calculate the length of the string
len() -> Gives integer output
BASIC STRING
FUNCTIONS
min() -> To calculate the minimum /maximum character among the
max( string
)
-> Check according to ASCII value
COVERTINGSTRING
capitalize()
FUNCTIONS
-> Only First character capitalized
COVERTINGSTRING
title()
FUNCTIONS
-> First character
capitalized in each word
istitle()
-> Checks whether it is in
title case or not
COVERTINGSTRING
lower()
FUNCTIONS
-> All character converted to lowercase
upper() -> All character converted to uppercase
COVERTINGSTRING
swapcase()
FUNCTIONS
-> Lower case letters are converted to Uppercase and
Uppercase letters are converted to Lowercase
COVERTINGSTRING
FUNCTIONS
replace(old,new) -> Replaces old string with new string
Testing String/Character
islower() -> Returns true if all characters in string are lowercase letters
Testing String/Character
isupper()
-> Returns true if all characters in string are uppercase letters
Testing String/Character
isalpha()
-> Returns true if all characters in string are alphabetic
Testing String/Character
isdigit() -> Returns true if string contains only number character
Testing String/Character
isspace()
-> Returns true if string
contains only whitespace
characters
Testing String/Character
isalnum(
)
-> Returns true if all
characters in string are
alphanumeric and there is
at least one character
Searching for substring
endswith(
)
-> Returns true if the
strings ends with the
substring
startswith(
)
-> Returns true if the
strings starts with the
substring
Searching for substring
find()
-> Returns the lowest
index or -1 if substring not
found
->You can mention the
range also
Searching for
Substring
index()
-> Returns the lowest index
or raise value error
exception if substring not
found
->You can mention the
range also
Searching for substring
count()
-> Returns the number of
occurrences of substring
You can mention the range
also
Removing Space within the String
lstrip() rstrip() strip()
-> Removes the -> Removes the
-> Removes the
leading Spaces leading as well as
trailing Spaces
the trailing Spaces
String Format Functions
center(width) -> Returns a string centered in a field of given
width
ljust(width) -> Returns a string left justified in a field of given
width
rjust(width) -> Returns a string right justified in a field of given
width
String Format Functions
format() -> Formats specified values in a string
String Split function – It splits a string based
on a character
split(
Default separator is
) space
split(char
)
String Split function – It splits a string based
on a character
Number represent the maximum index in the
split(char,number) list
NOTE : If two separator character are present consecutively then an empty string is
marked
String partition function – It splits a
string based on a character
partition(char) Splits the string based on the first occurrence of
the character
split Vs
partition
Split Partition
Split the string at each Split the string at first occurrence
occurrence of the delimiter of the delimiter character
character
It return List with variable It always return tuple with fixed
number of elements three element
Default delimiter is space If delimiter is not mentioned , it
will raise TypeError
Other Functions
isidentifier(
)
-> Check if the
string is a valid
string identifier or
not
Other Functions
join()
-> It joins a string or character after
each element of the sequence
Other Functions
sort()
Strings are sorted alphabetically
Return list of characters
LIST
Store any
type of data
Enclosed in
[ ] ,Elements
Slicing separated by
comma
LIS
Ordered
T
Concatenatio
/ n/ Replication
/ Membership
Indexed
Mutable
Concatenation Operator in List
List with
Two list other
sequence
EMPTY LIST EMPTY LIST
(using (using
brackets) constructor)
TYPE
OF LIST
NESTED LIST LONG LIST
CREATING
LIST
USER
STATIC ME FROM SEQ
THOD UENCES INPUT
Through Through Using eval
String Tuple ()
INDIVIDUAL
ACCESSING ELEMENT
USING IN
LIST ACCESSING
ALL
ELEMENT
USING RAN
GE()
List Functions
len()
Works only with numeric
sum() values
Works only with
Homogeneous values ,
min() Whether
1. All numeric values
2. All String value
3. All list/tuple value
max()
Adding Elements to
List
Append Extend Insert
Adds single value to Adds a list to Adds a value at a
list List/merging of list particular position
insert(position ,
value)
Adds a value at a particular
position
At given At first At last When positive index When negative
position position position out of bound index out of bound
# Positive Index Adds element at last
# Negative Index Adds element at begin
Removing elements from
List
pop() : Removes value from list
Removing elements from
List
remove() : Removes first occurrence of given value from
list
Removing elements from
List
clear() : Removes all elements from list and left it empty
Removing elements from
del : List
Removes single ,all or slice of elements from
list
List Functions
index () : Gives the index of the
passed value
List Functions
reverse () : Reverses the list element
within the list
It does not return anything
List Functions
sorted(
sort()
)
Sorts the list in
place Creates a new sorted list,
Does not affect the original list
It only works with
list
It can work with any sequence but
always result in list
With List With Other
sequence
Copying a List
Using constructor Using copy method Using Slicing
* Above methods create two separate list occupying
different memory where as simple assignment like
M=L , will create only two references.
TUPLE
Store any
type of data
Enclosed in
() ,Elements
Slicing separated by
comma
TUP
LE
Ordered / Concatenatio
n/ Replication
Indexed / Membership
Immutable
EMPTY tuple EMPTY tuple
(using (using
brackets) constructor)
TYPE
OF
TUPLE
NESTED tuple LONG tuple
CREATING
TUPLE
USER
STATIC ME FROM SEQ
THOD UENCES INPUT
Through Through Using eval
String list ()
What is the main
lists and tuples? difference between
The main difference between tuples and lists is that tuples are
immutable, meaning their contents cannot be changed after creation,
while lists are mutable and can be modified.
When would you prefer tuple over list?
Advantages of tuple over list in python are that they can be sorted,
iterated and they maintain their order automatically.
INDIVIDUAL
ACCESSING ELEMENT
USING IN
TUPLE ACCESSING
ALL
ELEMENT
USING RAN
GE()
Single Element
Tuple
T=(5) # python interpreter would consider it as an integer as
numbers can be enclosed in brackets
So , to represent single element tuple , we should use comma(,)
after the number
T=(5,)
Or
T=5, # as brackets are
optional
T=1,2,3
Tuple Functions
len()
Works only with numeric
sum() values
Works only with
Homogeneous values ,
min() Whether
1. All numeric values
2. All String value
3. All list/tuple value
max()
Functions of Tuple
index
()
count
()
Functions of Tuple
sorted(
)
Immutable Type with mutable
element
An immutable Tuple can store mutable elements & its
mutable elements can be changed.
“Immutable object remains the same but are not always
have the same abstract value”
Similarities between list and
tuple
Len()
Slicing
Indexing
Membership
Concatenation
Replication
Deleting Tuple
Indirectly Modifying
Tuples
1 Using Constructor list() and tuple()
Indirectly Modifying
Tuples
2 Unpacking Tuples :
creating individual values from tuple elements is called
unpacking .
creating a tuple from a set of values is known as packing
DICTIONARY
Characteristi
cs
Mutable
Unordered collection
Known as Associative array/mapping/Hashes
Store element in Key : value pair
Indexed on keys
Keys must be unique and immutable
Value can be duplicate
IMMUTABLE
KEY If not then generated
unhashable error
DICTIONARY ELEMENT
{} Separated by comma
MUTABLE /
VALUE
IMMUTABLE
D={'vowel1':'a','vowel2':'e'
}
Dictionary Key Value
CREATING DICTIONARIES :
my_dict = {"key1": "value1", "key2":
"value2"}
my_dict = dict(key1="value1",
key2="value2")
my_dict = dict([("key1", "value1"), ("key2",
"value2")])
keys = ["key1", "key2"]
values = ["value1", "value2"]
my_dict = dict(zip(keys, values))
Accessing Element of a
Dictionary
Accessing via Keys
(dict[key]):
Using get()
Method:
Accessing Element of a
Dictionary
Using keys()
Method:
Using values()
Method:
Accessing Element of a
Dictionary
Using items()
Method:
Iterating Through
Dictionary:
Adding / Updating elements in a
Dictionary
If key is not AD
present: D
If key is already UPDAT
present: E
Removing elements
from DICTIONARY
pop() : Removes element from dictionary and return
value
popitem() : Removes last element , if empty it gives key
error
clear() : Removes all elements from dictionary and left it
empty
del() : Removes single or all elements from
dictionary
del() : Removes single or all elements from
dictionary
Checking for
existence
Membership operator only checks keys
Dictionary
Functions
len() Works only with
Homogeneous keys ,
Whether
1. All numeric values
2. All String value
min() 3. All tuple value
max()
sum() Works only with numeric
keys
Dictionary
Function
SORTED() : -> Always return List
-> Keys must be homogenous to work upon
Dictionary
Key Function
merge
different
Update()
Key
update
same
SHALLOW COPY