Untitled

Run Settings
LanguagePython
Language Version
Run Command
# 14Jan2026 # Class 4 ''' l=[1,2,3,4,5] print(len(l),l[0],l[-5]) print(l[-1],l[4]) print(x) print(x, type(x)) l=[1,2,3,4,5] x = slice(2,4,1) #slice(starting, ending-1, + no of steps) print(l[x]) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19] x=slice(2,18,7) print(l[x]) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88] #25 x=slice(11,22,5) # 25 - 22 ==> 12,17,66 print(len(l), l[x]) print(l[::]) print(l[::2]) print(l[::4]) print(l[:12]) print(l[5:12]) l.append(99) print(l) l.insert(2,1000) # position#, value print(l) del l[:10:2] print(l) l.remove(13) print(l) y=l.pop(0) print(y,l) print(id(l)) #l=[] l.clear() print(id(l),l) ''' l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88] l2=[77,88,99] l2=l2+l #print(l2) l3=l2.copy() print(l3, id(l3)) l4=list(l3) print(l4, id(l4)) l5=l4[::] print(l5) print(l[::-1]) #flip the list, print from right to left l.reverse() print(l) l2=l[::-1] print(l2) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13] #25 x=slice(11,22,5) # 25 - 22 ==> 12,17,66 l2=l[::-1] print(l2) print(l) l.reverse print(l) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13] #25 l.sort() print(l) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13] #25 l2=sorted(l) #must remember sort and sorted print(l) print(l2) l=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13] #25 print(l.index(11)) print(l.count(13)) #tuple l=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13 #no need bracket for tuple but most people use ( ) print(type(l), l) #l[0]=2 l=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,34,78,66,101,23,88,13 #no need bracket for tuple but most people use ( ) l2=1,2,3 print(id(l2)) l2=l2+l print(id(l2),l2) l1=1,3,2,4,5 l2=99,88,77 l3=list(l1) l3.sort() l3=tuple(l3) #since tuple cannot be amended, it can not be sorted print(l3) l4=sorted(l2) l4=tuple(l4) print(l4) l6=1, # if tuple only 1 element, need a comma l7=() # for empty tuple needs a comma print(type(l6), type(l7)) x,y=1,2 #both x,y and 1,2 are tuple destructure the tuple this is what we need to know in python x=x+1 print(x,y) print(type(x), type(y)) ''' (x,y)=(1,2,3) print(type(x),type(y)) (x,y)=(1,) print(type(x),type(y)) (x,y)=(1,), print(type(x),type(y)) (x,y)=(1,),1 print(type(x),type(y)) ''' x,y=1,1 x, y=x,x print(x,y) x,y=1,10 x, y=x,x print(x,y) x,y=1,10 x, y = y,x print(x,y) x=1 y=10 temp=x x=y y=temp # in the older daus we use this to swap, but actually use tuple is shorter way to so it, and it is specialities of python #dictionary ''' Person Name="MARK" AGE=18 GENDER="MALE" Person = { "Name":"MARK", "AGE":18, "GENDER":"MALE" } ''' person={"name":"Mark","age":18,"gender":"female"} print(person, type(person)) print(person["name"]) name="name" person={name:"Mark","age":18,"gender":"female"} print(person, type(person)) print(person[name]) name="name" name_value="Mark" person={name:name_value,"age":18,"gender":"female"} print(person, type(person)) print(person[name])
Editor Settings
Theme
Key bindings
Full width
Lines