Page 442 - ComputerScience_Class_11
P. 442
Output
The items in Fruits are: ['Apple', 'Banana', 'Mango', 'Grapes', 'Orange']
Note: A list is like a shopping bag. We can put things in, take things out, rearrange them or even put two
of the same item inside.
Different Ways to Use a List
A list in Python can be created and used in different ways depending on the type of data stored and the structure
required. Some common ways to use a list are given below:
1. Basic Lists: A basic list is a list that stores elements of the same data type. The elements are written inside square
brackets [] and separated by commas.
Program 7: To store the same type of values in a single list variable.
Program 7.py
File Edit Format Run Options Window Help
# Creating a basic list of colours
Colour = ["Red", "Blue", "Yellow", "Green"]
# Printing the list
print("The items of colour are:", Colour)
Output
The items of colour are: ['Red', 'Blue', 'Yellow', 'Green']
2. Mixed List: A mixed list is a list that stores different types of data in one list. Its elements do not need to be of the
same data type and can include integers, strings, floats and Boolean values together.
Program 8: To store various types of data in a single list.
Program 8.py
File Edit Format Run Options Window Help
# Creating a list with mixed data types
data = ["Rahul", 21, 5.8, True]
# Printing the list
print("The mixed data is:", data )
Output
The mixed data is: ['Rahul', 21, 5.8, True]
440 Touchpad Computer Science (Ver. 3.0)-XI

