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

WorkSheet 2 - Python Lists

This document contains a Python worksheet on working with lists. It demonstrates how to create and modify lists by adding, removing, and accessing elements; slicing lists; concatenating lists; checking the length of lists; and iterating through lists using a for loop. The worksheet contains 18 code examples performing common list operations in Python like printing, modifying, appending, removing, slicing, and looping through elements of a list.

Uploaded by

Rloofy nami
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)
179 views

WorkSheet 2 - Python Lists

This document contains a Python worksheet on working with lists. It demonstrates how to create and modify lists by adding, removing, and accessing elements; slicing lists; concatenating lists; checking the length of lists; and iterating through lists using a for loop. The worksheet contains 18 code examples performing common list operations in Python like printing, modifying, appending, removing, slicing, and looping through elements of a list.

Uploaded by

Rloofy nami
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/ 3

Hamad bin Abdullah C2 C3

CCDI
Pyhon WorkSheet1

Name: Subject: CCDI


Class: Python List
Date:

1 # Creating a list
my_list = [1, 2, 3, 4, 5]
print(my_list)
2 # Accessing elements by index
prin# Creating a list
my_list = [1, 2, 3, 4, 5]
print(my_list)

3
# Accessing elements by index
print(my_list[0])
print(my_list[2])

4 # Modifying elements
my_list[1] = 6
print(my_list)

5 # Adding elements to the end of the


list
my_list.append(7)
print(my_list)

6 # Removing elements by value


my_list.remove(3)
print(my_list)
‫قطاع العمليات المدرسية‬
, 2 :‫ النطاق‬3 :‫المجلس‬
‫بنين‬2‫مدرسة حمد بن عبدهللا الشرقي ح‬

7 # Removing elements by index


del my_list[2]
print(my_list)
8 # Checking the length of the list
print(len(my_list))

9 # Iterating through a list using a


for loop
for item in my_list:
print(item)

10 # Slicing a list
subset = my_list[1:3]
print(subset)

11 # Concatenating lists
another_list = [8, 9]
combined_list = my_list +
another_list
print(combined_list)
print (my_list[0])
print(my_list[2])
12 # Modifying elements
my_list[1] = 6
print(my_list)

13 # Adding elements to the end of the


list
my_list.append(7)
print(my_list)

14 # Removing elements by value


my_list.remove(3)
print(my_list)

15 # Removing elements by index


del my_list[2]
‫قطاع العمليات المدرسية‬
, 2 :‫ النطاق‬3 :‫المجلس‬
‫بنين‬2‫مدرسة حمد بن عبدهللا الشرقي ح‬

print(my_list)

# Checking the length of the list


print(len(my_list))

16 # Iterating through a list using a


for loop
for item in my_list:
print(item)

17 # Slicing a list
subset = my_list[1:3]
print(subset)

18 # Concatenating lists
another_list = [8, 9]
combined_list = my_list +
another_list
print(combined_list)

You might also like