0% found this document useful (0 votes)
15 views

List in python

some basic concept of list in python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

List in python

some basic concept of list in python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python List Tutorial for Class IX Students

Introduction to Lists

• A list is a collection of items that are ordered and changeable. Lists are created using square
brackets [].
• Example:
• my_list = [1, 2, 3, 4, 5]
Key Features of Lists

1. Mutable: Elements can be changed after creation.


2. Ordered: Elements maintain the order of insertion.
3. Allows Duplicates: Multiple identical items are allowed.

Basic Operations on Lists

1. Access Elements:
Use index numbers, starting from 0.
2. my_list = [10, 20, 30]
3. print(my_list[0]) # Output: 10
4. Modify Elements:
5. my_list[1] = 25
6. print(my_list) # Output: [10, 25, 30]
7. Add Elements:
o Append an element:
o my_list.append(40)
o print(my_list) # Output: [10, 25, 30, 40]
o Insert an element:
o my_list.insert(2, 35)
o print(my_list) # Output: [10, 25, 35, 30, 40]
8. Remove Elements:
o Remove a specific element:
o my_list.remove(25)
o print(my_list) # Output: [10, 35, 30, 40]
o Remove by index:
o my_list.pop(2)
o print(my_list) # Output: [10, 35, 40]
9. Loop through a List:
10. for item in my_list:
11. print(item)

20 Questions on Lists
Section A: Basic Questions

1. Q1: Create a list of 5 fruits and print it.


Answer:
2. fruits = ["apple", "banana", "cherry", "date", "elderberry"]
3. print(fruits)
4. Q2: Access and print the 3rd element in a list:
Answer:
5. my_list = [5, 10, 15, 20]
6. print(my_list[2]) # Output: 15
7. Q3: Add "grape" to the list of fruits.
Answer:
8. fruits.append("grape")
9. print(fruits)
10. Q4: Insert "kiwi" at the 2nd position in the list of fruits.
Answer:
11. fruits.insert(1, "kiwi")
12. print(fruits)
13. Q5: Remove "banana" from the list.
Answer:
14. fruits.remove("banana")
15. print(fruits)
16. Q6: Find the length of the list my_list = [10, 20, 30, 40].
Answer:
17. print(len(my_list)) # Output: 4
18. Q7: Sort the list [30, 10, 20] in ascending order.
Answer:
19. numbers = [30, 10, 20]
20. numbers.sort()
21. print(numbers) # Output: [10, 20, 30]
22. Q8: Reverse the list [1, 2, 3, 4].
Answer:
23. numbers = [1, 2, 3, 4]
24. numbers.reverse()
25. print(numbers) # Output: [4, 3, 2, 1]

Section B: Intermediate Questions

9. Q9: Create a list from user input.


Answer:
10. user_input = input("Enter numbers separated by space: ")
11. my_list = user_input.split()
12. print(my_list)
13. Q10: Replace the 2nd element of a list with "mango".
Answer:
14. fruits[1] = "mango"
15. print(fruits)
16. Q11: Check if "apple" is in the list.
Answer:
17. if "apple" in fruits:
18. print("Yes")
19. Q12: Count how many times 5 appears in [1, 5, 5, 3, 5].
Answer:
20. numbers = [1, 5, 5, 3, 5]
21. print(numbers.count(5)) # Output: 3
22. Q13: Merge two lists [1, 2] and [3, 4].
Answer:
23. list1 = [1, 2]
24. list2 = [3, 4]
25. merged = list1 + list2
26. print(merged) # Output: [1, 2, 3, 4]
27. Q14: Iterate through a list and print even numbers only.
Answer:
28. numbers = [1, 2, 3, 4]
29. for num in numbers:
30. if num % 2 == 0:
31. print(num)

Section C: Advanced Questions

15. Q15: Copy a list without affecting the original list.


Answer:
16. original = [1, 2, 3]
17. copy = original.copy()
18. copy.append(4)
19. print(original) # Output: [1, 2, 3]
20. print(copy) # Output: [1, 2, 3, 4]
21. Q16: Find the maximum and minimum values in [10, 20, 30, 40].
Answer:
22. numbers = [10, 20, 30, 40]
23. print(max(numbers)) # Output: 40
24. print(min(numbers)) # Output: 10
25. Q17: Remove duplicates from [1, 2, 2, 3, 3, 4].
Answer:
26. numbers = [1, 2, 2, 3, 3, 4]
27. unique = list(set(numbers))
28. print(unique) # Output: [1, 2, 3, 4]
29. Q18: Find the index of the first occurrence of 30 in [10, 20, 30, 40, 30].
Answer:
30. numbers = [10, 20, 30, 40, 30]
31. print(numbers.index(30)) # Output: 2
32. Q19: Multiply each element in [1, 2, 3] by 2.
Answer:
33. numbers = [1, 2, 3]
34. doubled = [num * 2 for num in numbers]
35. print(doubled) # Output: [2, 4, 6]
36. Q20: Create a list of squares for numbers 1 to 5.
Answer:
37. squares = [num ** 2 for num in range(1, 6)]
38. print(squares) # Output: [1, 4, 9, 16, 25]

These questions cover basic, intermediate, and advanced list operations to give students a
comprehensive understanding of Python lists.

You might also like