Page 269 - CTS - CSA TP - Volume 2
P. 269
COMPUTER SOFTWARE APPLICATION - CITS
EXERCISE 128 : Write program in python using list, tuples,
dictionaries and files
Objectives
At the end of this exercise you shall be able to
• develop python program to use list, tuples, dictionaries and files.
Procedure
Python List:
In Python, a list is a versatile and commonly used data structure that allows you to store and manipulate a
collection of elements. Here’s a brief practical explanation of Python lists:
Creating Lists:
You can create a list by enclosing elements in square brackets [ ]. Elements can be of any data type, and a list
can contain a mix of different types.
Accessing Elements:
You can access elements in a list using indexing. Python uses 0-based indexing, meaning the first element is at
index 0.
Slicing Lists:
You can extract a portion of a list using slicing. Slicing is done using the colon : operator.
Modifying Lists:
Lists are mutable, meaning you can change their elements.
List Methods:
Python provides several built-in methods for manipulating lists, such as append(), remove(), pop(), extend(), and
more.
254