About Lesson
Classroom
PowerShell
Microsoft Windows [Version 10.0.19045.5073]
(c) Microsoft Corporation. All rights reserved.
C:\Users\Digital>py
Python 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[]
>>> a
[]
>>> a.append(15)
>>> a
[15]
>>> a.append("Sheetal Mathur")
>>> a
[15, 'Sheetal Mathur']
>>> a.append(11.5)
>>> a
[15, 'Sheetal Mathur', 11.5]
>>> a.insert(1,"Hello")
>>> a
[15, 'Hello', 'Sheetal Mathur', 11.5]
>>> a.index("Hello")
1
>>> len(a)
4
>>> a.remove("Sheetal Mathur")
>>> a
[15, 'Hello', 11.5]
>>> a.reverse()
>>> a
[11.5, 'Hello', 15]
>>> a.sort()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'float'
>>> b = ["Apple","Mango","Litchi","Orange","Banana"]
>>> b
['Apple', 'Mango', 'Litchi', 'Orange', 'Banana']
>>> b.sort()
>>> a
[11.5, 'Hello', 15]
>>> b
['Apple', 'Banana', 'Litchi', 'Mango', 'Orange']
>>> c=tuple(b)
>>> c
('Apple', 'Banana', 'Litchi', 'Mango', 'Orange')
>>> d=list(c)
>>> d
['Apple', 'Banana', 'Litchi', 'Mango', 'Orange']
>>> b.pop(2)
'Litchi'
>>> b
['Apple', 'Banana', 'Mango', 'Orange']
>>> type(d)
<class 'list'>
>>> name = ["Anil","Sunil","Ram","Sham","Aman"]
>>> name
['Anil', 'Sunil', 'Ram', 'Sham', 'Aman']
>>> for i in name:
... print(i)
...
Anil
Sunil
Ram
Sham
Aman
>>> n=tuple(name)
>>> n
('Anil', 'Sunil', 'Ram', 'Sham', 'Aman')
>>> type(n)
<class 'tuple'>
>>> n[4]
'Aman'
>>> n[0]
'Anil'
>>> n[-1]
'Aman'
>>> b
['Apple', 'Banana', 'Mango', 'Orange']
>>> del b
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> num = (43,22,44,12,89,77)
>>> max(num)
89
>>> min(num)
12
>>> num.sort()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'sort'
>>> len(num)
6
>>> num
(43, 22, 44, 12, 89, 77)
>>> 22 in num
True
>>> 55 in num
False