Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep 6 2024, 20:11:23) [MSC v.
1940 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license()" for more information.
l=[10,20,30,40,50,60,70,80,90]
[10, 20, 30, 40, 50, 60, 70, 80, 90]
l[1]
20
l[-1]
90
l[0]=1
[1, 20, 30, 40, 50, 60, 70, 80, 90]
l[-1]=9
[1, 20, 30, 40, 50, 60, 70, 80, 9]
l[-2]=8
l[-3]=7
[1, 20, 30, 40, 50, 60, 7, 8, 9]
m=[34,'sagir',9+2j,54.65]
[34, 'sagir', (9+2j), 54.65]
m[0]
34
m[0]=43
[43, 'sagir', (9+2j), 54.65]
m[1]
'sagir'
m[1][2]
'g'
m[1][2]=b
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
m[1][2]=b
NameError: name 'b' is not defined
m[1][2]='b'
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
m[1][2]='b'
TypeError: 'str' object does not support item assignment
m[2]
(9+2j)
m[2]=4+3j
[43, 'sagir', (4+3j), 54.65]
f=['your own name',23,3+6j,{1,3,5},(3,5,7),{2:22,3:33,4:44},[22,33,44]]
f[2]
(3+6j)
f[3]
{1, 3, 5}
f[3]={2,4,6}
['your own name', 23, (3+6j), {2, 4, 6}, (3, 5, 7), {2: 22, 3: 33, 4: 44}, [22, 33, 44]]
f[3][1]=6
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
f[3][1]=6
TypeError: 'set' object does not support item assignment
f[0]
'your own name'
f[0][-1]='f'
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
f[0][-1]='f'
TypeError: 'str' object does not support item assignment
f[0]='soham'
['soham', 23, (3+6j), {2, 4, 6}, (3, 5, 7), {2: 22, 3: 33, 4: 44}, [22, 33, 44]]
list()
[]
bool([])
False
bool(f)
True
[1, 20, 30, 40, 50, 60, 7, 8, 9]
#to add the value: append()=> var_name.append(value)
[Link](34)
[1, 20, 30, 40, 50, 60, 7, 8, 9, 34]
[Link](90)
[Link](15)
l
[1, 20, 30, 40, 50, 60, 7, 8, 9, 34, 90, 15]
id(l)
1885808434112
[Link](67)
[1, 20, 30, 40, 50, 60, 7, 8, 9, 34, 90, 15, 67]
id(l)
1885808434112
# to add all value at a time: extend()=>[Link]([val1,val2,....valn])
[Link]([91,55,140,4])
[1, 20, 30, 40, 50, 60, 7, 8, 9, 34, 90, 15, 67, 91, 55, 140, 4]
id(l)
1885808434112
[Link](3,'ram')
[1, 20, 30, 'ram', 40, 50, 60, 7, 8, 9, 34, 90, 15, 67, 91, 55, 140, 4]
#to remove the value: pop()=>[Link]()
[Link]()
[1, 20, 30, 'ram', 40, 50, 60, 7, 8, 9, 34, 90, 15, 67, 91, 55, 140]
[Link]()
140
[1, 20, 30, 'ram', 40, 50, 60, 7, 8, 9, 34, 90, 15, 67, 91, 55]
[Link]()
55
[1, 20, 30, 'ram', 40, 50, 60, 7, 8, 9, 34, 90, 15, 67, 91]
[Link](9)
[1, 20, 30, 'ram', 40, 50, 60, 7, 8, 34, 90, 15, 67, 91]
[Link](9)
34
#if [Link](index)=> that index value will bw removed but if user don't put any index it will
removed from the last value.
# to remove the particular value from the list we can use remove() function:
[Link](value)
[Link]('ram')
[1, 20, 30, 40, 50, 60, 7, 8, 90, 15, 67, 91]
[Link](3:6)
SyntaxError: invalid syntax
[Link][1:3]
Traceback (most recent call last):
File "<pyshell#68>", line 1, in <module>
[Link][1:3]
AttributeError: 'list' object has no attribute 'delete'
dir(list)
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__',
'__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
'__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__',
'__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
'__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index',
'insert', 'pop', 'remove', 'reverse', 'sort']
import keyword
[Link]
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def',
'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
del l[3]
[1, 20, 30, 50, 60, 7, 8, 90, 15, 67, 91]
del l[2:4]
[1, 20, 60, 7, 8, 90, 15, 67, 91]
# del var[strarting index: ending index+1]