0% found this document useful (0 votes)
18 views5 pages

Python Lists and Tuples Operations

This document contains a series of Python list and tuple operations performed by Anirudha Jadhav. It includes examples of creating lists, accessing elements, modifying lists through append, pop, insert, and count methods, as well as demonstrating list slicing and sorting. The document also highlights error handling with an IndexError when accessing an out-of-range index.

Uploaded by

anya jadhav
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)
18 views5 pages

Python Lists and Tuples Operations

This document contains a series of Python list and tuple operations performed by Anirudha Jadhav. It includes examples of creating lists, accessing elements, modifying lists through append, pop, insert, and count methods, as well as demonstrating list slicing and sorting. The document also highlights error handling with an IndexError when accessing an out-of-range index.

Uploaded by

anya jadhav
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

Experiment No:05

List & Tuples


Name: Anirudha Jadhav
Roll No:42
[1,2,3]

[1, 2, 3]

a=[1,2,3]
type(a)

list

len(a)

b=['Anirudha','hari','sham']
c=[1,2,1.4]
d=[True,False]
d

[True, False]

a=[1,2,3,111,'Anirudha']
a[0]

a[5]

----------------------------------------------------------------------
-----
IndexError Traceback (most recent call
last)
Cell In[9], line 1
----> 1 a[5]

IndexError: list index out of range

a[3]

a[4]

a[::-1]
a

a[4][::-1]

a[1:4]

a[:]

a[0:]

a[:5]

a[:100]

a[2]

a[2]='sleep'

a=[1,2,3,3,4,5]
a

a=[123,44,'Anirudha',[7,8,9]]
a[3]

a[3][1]

a[0][1]

str(a[0])[1]

a=[1,2,3,[4,5,6,[7,8,9]]]
a[3]

a[3][3][0]

a=[1,2,3]
print(type(a))
print(len(a))
d=[True,False]
print(d)
a=[1,2,3,111,'Anirudha']
print(a[0])
print(a[3])
print(a[4])
print(a[::-1])
print(a[4][::-1])
print(a[1:4])
print(a[:])
print(a[0:])
print(a[:5])
print(a[:100])
print(a[2])
a[2]='sleep'
print(a)
a=[1,2,3,3,4,5]
print(a)
a=[123,44,'Anirudha',[7,8,9]]
print(a[3])
print(a[3][1])
print(str(a[0])[1])
a=[1,2,3,[4,5,6,[7,8,9]]]
print(a[3])
print(a[3][3][0])

Operations
a=[123,1.1,33,'Anirudha']
a

[123, 1.1, 33, 'Anirudha']

[Link]('hari')

[123, 1.1, 33, 'Anirudha', 'hari']

[Link]()

'hari'

[123, 1.1, 33, 'Anirudha']

[Link](3,'sham')

[123, 1.1, 33, 'sham', 'Anirudha']

[Link](4,'abc')

[123, 1.1, 33, 'sham', 'abc', 'Anirudha']

[Link](33)

a[1]=33

a
[123, 33, 33, 'sham', 'abc', 'Anirudha']

[Link](33)

a[2:].index(33)

a1=[Link]()
a1

[123, 33, 33, 'sham', 'abc', 'Anirudha']

[Link]()

a1

[]

[Link]()
a

['Anirudha', 'abc', 'sham', 33, 33, 123]

a1=[7,8,9]
a2=a+a1
a2

['Anirudha', 'abc', 'sham', 33, 33, 123, 7, 8, 9]

a9=['gopi','hari','Anirudha']
[Link]()
a9

['Anirudha', 'gopi', 'hari']

a=[123,1.1,33,'Anirudha']
print(a)
print('Append Operation')
[Link]('hari')
print(a)
print('Pop Operation')
[Link]()
print(a)
print('Insert Operation')
[Link](3,'sham')
print(a)
[Link](4,'abc')
print(a)
[Link](33)
print('Count Operation on 33 :',[Link](33))
a[1]=33
print(a)
[Link](33)
print('Count Operation on 33 :',[Link](33))
print('Index Operation :',a[2:].index(33))
a1=[Link]()
print('Copy Operstion:')
print(a1)
print([Link]())
print('Clear Operation')
print(a1)
print('Reverse Oporation :')
[Link]()
print(a)
a1=[7,8,9]
a2=a+a1
print(a2)
a9=['gopi','hari','Anirudha']
[Link]()
print('Sort Operation :')
print(a9)

[123, 1.1, 33, 'Anirudha']


Append Operation
[123, 1.1, 33, 'Anirudha', 'hari']
Pop Operation
[123, 1.1, 33, 'Anirudha']
Insert Operation
[123, 1.1, 33, 'sham', 'Anirudha']
[123, 1.1, 33, 'sham', 'abc', 'Anirudha']
Count Operation on 33 : 1
[123, 33, 33, 'sham', 'abc', 'Anirudha']
Count Operation on 33 : 2
Index Operation : 0
Copy Operstion:
[123, 33, 33, 'sham', 'abc', 'Anirudha']
None
Clear Operation
[]
Reverse Oporation :
['Anirudha', 'abc', 'sham', 33, 33, 123]
['Anirudha', 'abc', 'sham', 33, 33, 123, 7, 8, 9]
Sort Operation :
['Anirudha', 'gopi', 'hari']

You might also like