Page 228 - Bilgisayar Bilimi | Kur 1
P. 228
Örnek
a=[10,20,30,40]
b=[10,20,30,40]
print(‘Is ‘,a, ‘ equal to ‘,b, ‘?’,sep=’’,end=’ ‘)
print(a==b)
print(‘Are ‘,a, ‘ and ‘,b, ‘ aliases?’,sep=’’,end=’ ‘)
print(a is b)
c=[100,200,300,400]
d=c
print(‘Is ‘,c, ‘ equal to ‘,d, ‘?’,sep=’’,end=’ ‘)
print(c==d)
print(‘Are ‘,c, ‘ and ‘,d, ‘ aliases?’,sep=’’,end=’ ‘)
print(c is d)
Ekran Çıktısı
Is [10,20,30,40]equalto[10,20,30,40]?True
Are [10,20,30,40]and[10,20,30,40]aliases?False
Is [100,200,300,400]equalto[100,200,300,400]?True
Are [100,200,300,400]and[100,200,300,400]aliases?True
Örnek
def list _ copy(lst):
result=[]
for item in lst:
result+=[item]
return result
def main():
a=[10,20,30,40]
b=list _ copy(a)
print(‹a =›,a, ‹ b =›,b)
print(‹Is ‹,a, ‹ equal to ‹,b, ‹?›,sep=››,end=› ‹)
print(a==b)
print(‹Are ‹,a, ‹ and ‹,b, ‹ aliases?›,sep=››,end=› ‹)
print(a is b)
b[2]=35
print(‹a =›,a, ‹ b =›,b)
main()
227