Python List


1) Create a List

Create a list of 5 numbers and print it.


2) Access an Element

Given:

lst = [10, 20, 30, 40, 50]

Print the 3rd element.


3) Change an Element

Change the 2nd element in this list to 99 and print the list:

lst = [1, 2, 3, 4]

4) List Length

Create a list of 7 items and print its length using len().


5) Append to List

Start with:

Add "cherry" using append() and print.


6) Insert into List

Insert "orange" at index 1 in:

Print the updated list.


7) Remove an Item

Remove "apple" from:


8) Pop an Item

Create:

Remove the last item using pop() and print it.


9) Clear a List

Create a list and clear all items using clear().


10) Sum of Numbers

Create a list of numbers and print the sum of its items using a loop.


11) Max & Min

Create a numeric list and print its maximum and minimum using max() and min().


12) Slice a List

Given:

Print lst[1:5] and lst[:3].


13) List of Squares

Use a loop to create a list of squares from 1 to 10.


14) Count Occurrences

Create a list with repeating values and use count() to count how many times a value appears.

Example:


15) Join Two Lists

Combine:

into one list and print.


16) Check Membership

Ask user for a number and check if it’s in a list.


17) Reverse a List

Reverse a list using reverse().


18) Sort a List

Create:

Sort it in ascending order and print.


19) Loop with Index

Loop through a list and print:


20) Nested List Access

Given:

Print the value 3.


📝 Tips for Students

  • Use built-in functions: len(), append(), insert(), remove(), pop(), count(), sort(), reverse().

  • Access list items using indexes starting at 0.

  • For slicing:

    returns items from start up to but not including end.


canvil: 333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1

Last updated