0% found this document useful (0 votes)
2 views2 pages

Program Using List

The document contains two programs demonstrating the use of lists and tuples in Python. The first program manipulates a list of fruits by accessing, modifying, adding, removing, sorting, and reversing elements. The second program showcases tuple operations including accessing elements, counting, checking for existence, concatenating, and converting between tuples and lists.

Uploaded by

priyaganesh12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Program Using List

The document contains two programs demonstrating the use of lists and tuples in Python. The first program manipulates a list of fruits by accessing, modifying, adding, removing, sorting, and reversing elements. The second program showcases tuple operations including accessing elements, counting, checking for existence, concatenating, and converting between tuples and lists.

Uploaded by

priyaganesh12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Program using list

fruits=["Apple","Banana","Guava","Charry","Grape"]
print("First Fruit:",fruits[0])
print("Last Fruit:",fruits[-1])
#Modifying elements
fruits[1]="Blueberry"
print("Modified Fruits List:",fruits)
#Adding Elements
[Link]("Watermelon")
print("Fruits List after append:",fruits)
#Removing Elements
removedfruit=[Link](2)
print("removed Fruit:",removedfruit)
print(" Fruits List after removing:",fruits)
#length of the list
print ("Number of fruits",len(fruits))
#sorting fruits
[Link]()
print("Sorted fruits list:",fruits)
#reversing the list
[Link]()
print("Reversed fruit list:",fruits)

output:
First Fruit: Apple
Last Fruit: Grape
Modified Fruits List: ['Apple', 'Blueberry', 'Guava', 'Charry', 'Grape']
Fruits List after append: ['Apple', 'Blueberry', 'Guava', 'Charry', 'Grape', 'Watermelon']
removed Fruit: Guava
Fruits List after removing: ['Apple', 'Blueberry', 'Charry', 'Grape', 'Watermelon']
Number of fruits 5
Sorted fruits list: ['Apple', 'Blueberry', 'Charry', 'Grape', 'Watermelon']
Reversed fruit list: ['Watermelon', 'Grape', 'Charry', 'Blueberry', 'Apple']
[Link] using tuple

color=("Red","Green","Blue","Yellow")
#Accessing elements in the tuple
print("First color:",color[0])
print("Last color:",color[-1])
print("Slice of color:",color[1:3])
# Counting elements in the tuple
print("Number of colors:",len(color))
#checking if an element exits in the tuple
print("Is 'Red' in colors?","Red"in color)
print("Is 'Purple' in colors?","Purple"in color)
#concatenating tuples
color1=("orange","purple")
allcolors=color+color1
print("All colors:",allcolors)
#converting tuple to a list
colorlist=list(color)
print("Colors as a List",colorlist)
#converting list to a tuple
colortuple=tuple(colorlist)
print("Colors as a tuple",colortuple)

output
First color: Red
Last color: Yellow
Slice of color: ('Green', 'Blue')
Number of colors: 4
Is 'Red' in colors? True
Is 'Purple' in colors? False
All colors: ('Red', 'Green', 'Blue', 'Yellow', 'orange', 'purple')
Colors as a List ['Red', 'Green', 'Blue', 'Yellow']
Colors as a tuple ('Red', 'Green', 'Blue', 'Yellow')

You might also like