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

PDF&Rendition 1

The document consists of a series of Python code snippets demonstrating various list operations, including creation, modification, and manipulation of lists. It covers methods such as appending, extending, removing elements, and handling errors. The examples illustrate how to work with lists in Python, including indexing, slicing, and counting elements.
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)
9 views5 pages

PDF&Rendition 1

The document consists of a series of Python code snippets demonstrating various list operations, including creation, modification, and manipulation of lists. It covers methods such as appending, extending, removing elements, and handling errors. The examples illustrate how to work with lists in Python, including indexing, slicing, and counting elements.
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

In [1]:  l=[10,20,30,50]

Out[1]: [10, 20, 30, 50]

In [2]:  l=[]
l

Out[2]: []

In [3]:  l=list()
l

Out[3]: []

In [4]:  l=[10,20,30,50]
l[1]=2000
l

Out[4]: [10, 2000, 30, 50]

In [5]:  l=l+10
l

--------------------------------------------------------------------------
-
TypeError Traceback (most recent call las
t)
Cell In[5], line 1
----> 1 l=l+10
2 l

TypeError: can only concatenate list (not "int") to list

In [6]:  l*2

Out[6]: [10, 2000, 30, 50, 10, 2000, 30, 50]

In [7]:  l[:5:3]

Out[7]: [10, 50]

In [8]:  for i in l:
print(i)

10
2000
30
50
In [14]:  for i in range(len(l)):
print(l[i],end=" ")

10 2000 30 50

In [15]:  len(l)

Out[15]: 4

In [18]:  a=[Link](0)
a

Out[18]: 10

In [2]:  ​

--------------------------------------------------------------------------
-
NameError Traceback (most recent call las
t)
Cell In[2], line 1
----> 1 print(l)

NameError: name 'l' is not defined

In [19]:  l=[10,20,30,50]
sum(l)

Out[19]: 110

In [5]:  l=[10,20,5,50]
print([Link](reverse=True))
l

None

Out[5]: [50, 20, 10, 5]

In [26]:  l=[10,20,5,50]
print([Link](reverse=True))
l

None

Out[26]: [50, 20, 10, 5]


In [28]:  [Link]()
l

Out[28]: [50, 20, 10, 5]

In [29]:  l=[10,20,5,50,5,5]
[Link](5)

Out[29]: 3

In [30]:  [Link](1000)

Out[30]: 0

In [34]:  #Remove first occurance of an element


l=[10,20,50,400,50,50,50]
[Link](50)
l

Out[34]: [10, 20, 400, 50, 50, 50]

In [6]:  l=[10,20,50,400,50,50,50]
[Link]()
[Link]()
print(l)

[10, 20, 50, 400, 50]

In [39]:  l=[10,20,50,400,50,50,50]
[Link](500)
l

--------------------------------------------------------------------------
-
ValueError Traceback (most recent call las
t)
Cell In[39], line 2
1 l=[10,20,50,400,50,50,50]
----> 2 [Link](500)
3 l

ValueError: [Link](x): x not in list

In [38]:  l=[10,20,50,400,50,50]
del l[5]
l

Out[38]: [10, 20, 50, 400, 50]


In [40]:  l=[10,20,50,400,50,50]
del l[2:4]
l

Out[40]: [10, 20, 50, 50]

In [7]:  del l
l

--------------------------------------------------------------------------
-
NameError Traceback (most recent call las
t)
Cell In[7], line 2
1 del l
----> 2 l

NameError: name 'l' is not defined

In [41]:  l

Out[41]: [10, 20, 50, 50]

In [42]:  [Link](100)
l

Out[42]: [10, 20, 50, 50, 100]

In [44]:  [Link]([200,300,100])
l

Out[44]: [10, 20, 50, 50, 100, [200, 300, 100]]

In [45]:  [Link]([200,300,100])
l

Out[45]: [10, 20, 50, 50, 100, [200, 300, 100], 200, 300, 100]

In [46]:  #insert 5000 at 3rd index


[Link](3,5000)
l

Out[46]: [10, 20, 50, 5000, 50, 100, [200, 300, 100], 200, 300, 100]

In [ ]:  ​

You might also like