student = {"name": "Harshh", "class": 12, "score": 95}
Method / Function What it does Quick Example Result / Output
(Simple Meaning)
keys() Returns a list-like [Link]() dict_keys(['name',
object of all the keys 'class', 'score'])
in the dictionary.
values() Returns a list-like [Link]() dict_values(['Harshh',
object of all the 12, 95])
values in the
dictionary.
items() Returns all the [Link]() dict_items([('name',
key-value pairs as 'Harshh'), ('class', 12),
pairs of tuples. ('score', 95)])
(Super useful for
loops!)
get(key) Safely gets the value [Link]("score") 95
for a key. If the key
doesn't exist, it [Link]("age") None
returns None instead
of crashing your
code with an error.
update(dict) Adds key-value pairs [Link]({"age {"name": "Harshh",
from another ": 18}) "class": 12, "score": 95,
dictionary (or "age": 18}
updates existing
ones).
pop(key) Removes the [Link]("class") Returns 12.
specified key and
returns its value. Dict becomes {"name":
"Harshh", "score": 95}
clear() Completely empties [Link]() {} (an empty dictionary)
the dictionary.
len(dict) (Built-in function) len(student) 3
Tells you how many
key-value pairs are
inside.
del (Statement) Deletes a del student["score"] {"name": "Harshh",
specific key-value "class": 12}
pair permanently.
scores = [80, 95, 75, 95]
Method / Function What it does (Simple Quick Example Result /
Meaning) Output
append(item) Adds a single item to the [Link](100) [80, 95, 75,
very end of the list. 95, 100]
extend(iterable) Adds multiple items (like [Link]([60, 70]) [80, 95, 75,
another list) to the end. 95, 60, 70]
insert(index, item) Sneaks an item into a [Link](1, 99) [80, 99, 95,
specific position (index) 75, 95]
without deleting
anything.
remove(item) Removes the first [Link](95) [80, 75, 95]
occurrence of the (Notice only
specified value. the first 95 is
gone!)
pop([index]) Removes and returns [Link]() Returns 95.
the item at a specific
index. If you leave the
brackets empty, it pops
off the last item.
List becomes
[80, 95, 75]
count(item) Counts exactly how [Link](95) 2
many times an item
appears.
index(item) Tells you the index [Link](75) 2
position of the first
occurrence of an item.
sort() Sorts the list in [Link]() [75, 80, 95,
ascending order 95]
permanently. (Add
reverse=True inside the
brackets for
descending!)
reverse() Flips the list backwards [Link]() [95, 75, 95,
permanently. (It doesn't 80]
sort it, just flips the
current order).
len(list) (Built-in function) Tells len(scores) 4
you the total number of
items in the list.
text = "python EXAMS 99 "
Method / What it does (Simple Quick Example Result /
Function Meaning) Output
lower() Converts all letters to [Link]() "python exams
lowercase. 99 "
upper() Converts all letters to [Link]() "PYTHON
uppercase. EXAMS 99 "
capitalize() Makes only the very first [Link]() "Python
letter capital. exams 99 "
split([char]) Breaks the string into a list [Link]() ['python',
of words. (Usually splits at 'EXAMS', '99']
spaces if you leave
brackets empty).
replace(old, Swaps out a word or [Link]("99", "100") "python
new) character for a new one. EXAMS 100 "
find(sub) Finds the starting index of [Link]("EXAMS") 7
a word/letter. Returns -1 if it
can't find it.
strip() Removes any extra spaces [Link]() "python
from the very beginning EXAMS 99"
and the very end.
isalpha() Checks if the string has "Hello".isalpha() True
only alphabets (no spaces,
no numbers).
isdigit() Checks if the string has "2024".isdigit() True
only numbers.
isalnum() Checks if the string is just "Exam99".isalnum() True
alphabets and/or numbers
(no spaces or special
symbols).
vowels = ('a', 'e', 'i', 'o', 'u', 'a')
Method / What it does (Simple Meaning) Quick Example Result /
Function Output
count(item) Counts exactly how many times [Link]('a') 2
an item appears in the tuple.
index(item) Tells you the index position of the [Link]('i') 2
first occurrence of the item.
len(tuple) (Built-in function) Tells you the len(vowels) 6
total number of items.
set_a = {1, 2, 3}
set_b = {3, 4, 5}
Method / Function What it does (Simple Quick Example Result /
Meaning) Output
add(item) Adds a single item to set_a.add(9) {1, 2, 3, 9}
the set. (If it's already
there, nothing
happens).
remove(item) Removes a specific set_a.remove(2) {1, 3}
item. (Throws an error
if the item isn't there).
union(set) Combines two sets set_a.union(set_b) {1, 2, 3, 4,
together, keeping only 5}
unique items.
intersection(set) Returns only the items set_a.intersection(set_b) {3}
that are present in
both sets.
clear() Empties the entire set. set_a.clear() set()
(empty
set)