Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2 — List Operations

Lesson 28 of 50 in the free Python Programming notes on Siksha Sarovar, written by Rohit Jangra.

List Operations

OperationExampleResult
len()len([1,2,3])3
Concatenation +[1,2] + [3,4][1,2,3,4]
Repetition *[1,2] * 3[1,2,1,2,1,2]
in3 in [1,2,3]True
not in5 not in [1,2,3]True
max()max([3,1,4,1,5])5
min()min([3,1,4,1,5])1
sum()sum([1,2,3])6
all()all([1,1,0])False
any()any([0,0,1])True
a = [1, 2, 3]
b = [4, 5]

print(len(a))          # 3
print(a + b)            # [1, 2, 3, 4, 5]
print(a * 2)             # [1, 2, 3, 1, 2, 3]
print(3 in a)             # True
print(10 not in a)        # True

max(), min(), sum()

nums = [23, 5, 89, 12, 67]
print(max(nums))    # 89
print(min(nums))    # 5
print(sum(nums))    # 196
print(sum(nums) / len(nums))   # 39.2  (average)

all() and any()

all() returns True only if every element is truthy; any() returns True if at least one element is truthy.

marks = [45, 67, 89, 33]
print(all(m >= 40 for m in marks))   # False (33 < 40)
print(any(m >= 90 for m in marks))   # False (no one scored 90+)
print(any(m < 40 for m in marks))    # True  (33 failed)

print(all([1, 2, 3]))    # True  -- all non-zero
print(all([1, 0, 3]))    # False -- 0 is falsy
print(any([0, 0, 0]))    # False
print(any([0, 0, 5]))    # True

List Comprehension (bonus — concise list creation)

squares = [x ** 2 for x in range(1, 6)]
print(squares)              # [1, 4, 9, 16, 25]

evens = [x for x in range(20) if x % 2 == 0]
print(evens)                # [0, 2, 4, ..., 18]