In [1]:
l=[]
In [2]:
l=[2,'abc',3.0]
l
Out[2]:
In [4]:
l[0]=3
In [5]:
l
Out[5]:
In [6]:
l[1]
Out[6]:
In [1]:
l2=[3,5,[9,8.0],7]
l2[2]
len(l2)
Out[1]:
In [3]:
l2[2][0]
Out[3]:
In [9]:
l2[3]
Out[9]:
In [5]:
l2[3]
In [19]:
l3=list('i am indian')
l3
l4=str(l3)
len(l3)
print(len(l4))
In [12]:
eval('5'+'8')
Out[12]:
In [13]:
eval('8+9')
Out[13]:
In [14]:
eval('3*10')
Out[14]:
In [12]:
v=eval(input('enter value or expression'))
print(v,type(v))
In [20]:
vow="ae iou"
vowel=list(vow)
print(vow,vowel)
In [21]:
s=str(vowel)
print(s)
print(len(s),len(vow),len(vowel))
In [29]:
l1,l2=[1,2,3],[1,2,3]
l1==l2
l1!=l2
Out[29]:
In [32]:
Out[32]:
In [32]:
l1=l1+l2
In [33]:
l1
Out[33]:
In [34]:
l1+3
In [35]:
l1*2
Out[35]:
In [1]:
eval('5+8')
Out[1]:
In [2]:
eval('3*10')
Out[2]:
In [3]:
eval('3'*'10')
In [ ]:
v=eval(input('enter value'))
print(v,type(v))
In [ ]:
l1=(4,5,6)
l2=(6,7,8,)
In [ ]:
print(l1>l2)
print(l1<l2)
In [2]:
lst=[10,20,30,40,32,34,40,80,90,23]
se=lst[3:-3]
se
Out[2]:
In [3]:
se[1]
Out[3]:
In [4]:
lst[-12:7]
Out[4]:
In [5]:
lst[-12:10]
Out[5]:
In [6]:
lst[-24:24]
Out[6]:
In [7]:
lst[2:10:3]
Out[7]:
In [8]:
lst
Out[8]:
In [9]:
lst[1:3]=[12,34,56]
In [19]:
len(lst)
Out[19]:
In [11]:
lst[0:1]=[22,33,44,55,66]
In [14]:
len(lst)
Out[14]:
In [13]:
len(lst)
Out[13]:
In [17]:
lst[0:5]=[5,5]
In [18]:
lst
Out[18]:
In [21]:
fst=['i','you','we','they']
fst[0:2]=[45]
In [22]:
fst
Out[22]:
In [23]:
L=[1,2,3]
L[2:]='604'
L
Out[23]:
In [24]:
L1[2:]=604
In [26]:
L1=['a','b','c']
L1[10:20]='xyz'
In [27]:
L1
Out[27]:
In [29]:
L1+='16'
In [31]:
L1*=2
In [32]:
L1
Out[32]:
In [34]:
L1=['11','22','33','44','55']
L1
Out[34]:
In [35]:
L1.append(16)
In [36]:
del L1[0]
In [37]:
L1
Out[37]:
In [38]:
del L1[0:1]
In [39]:
L1
Out[39]:
In [40]:
del L1[0:2]
In [41]:
L1
Out[41]:
In [42]:
L1+=[11,12,15,40]
In [1]:
L1
In [45]:
L1.pop(-1)
Out[45]:
In [46]:
L1
Out[46]:
In [47]:
L1
Out[47]:
In [48]:
L2
In [49]:
#list copy
c=[1,2,3]
d=c
Out[49]:
In [55]:
c[1]=9
print(c)
print(d)
#reflect change in both
In [53]:
#seperate copy list
a=[10,20,30]
b=list(a)
b[1]=40
print(a)
print(b)
In [4]:
#copied list reference original List
c=[1,2,3]
d=c
d[1]=9
print(c)
print(d)
In [58]:
#index function in List
L1=[13,18,20,18,28,20,35]
print(L1.index(18))
print(L1.index(20))
In [62]:
#append in List
L2=[]
L2.append(90)
L2.append('ninty')
L3=L2.append('ten')
print(L2)
print(L3)
In [2]:
l1=[1,2,3]
l1+=[5,6]
In [3]:
l1
Out[3]:
In [2]:
t1=[1,2,3]
t2=[4,5,6]
t1.extend(t2)
t1+=t2
t1
Out[2]:
In [4]:
t1=[3,4,5]
t1.insert(1,9)
t1
Out[4]:
In [20]:
#index value if more than max index
t1.insert(7,5)
t1
Out[20]:
In [7]:
#index value if less than min index
t1.insert(-8,88)
t1
Out[7]:
In [10]:
#it will remove all element from list
t1.clear()
t1
Out[10]:
In [23]:
#count number of item freuency in list
t1=[1,2,2,3,3,3,4,4,5,5]
t1.count(3)
Out[23]:
In [12]:
t1.count(2)
Out[12]:
In [13]:
t1.count(3)
Out[13]:
In [14]:
t1.reverse()
t1
Out[14]:
In [15]:
t1.sort()
In [16]:
t1
Out[16]:
In [17]:
t1.sort(reverse=True)
In [18]:
t1
Out[18]:
In [21]:
t1=[1,2,3]
t1.insert(7,5)
t1
Out[21]:
In [24]:
l=['abc','zxzx','nnnn','aaa']
l.sort()
l
Out[24]:
In [27]:
l.sort(reverse=False)
l
Out[27]:
In [28]:
l=['A','B','aaa']
l.sort()
l
Out[28]:
In [29]:
ord(1)
In [30]:
chr(1)
Out[30]:
In [31]:
chr(97)
Out[31]:
In [32]:
ord('A')
Out[32]:
In [33]:
ord('1')
Out[33]:
In [34]:
ord('a')
Out[34]:
In [ ]:
No comments:
Post a Comment