Kod: Tümünü seç
liste1 = ['index0', 1, 2.1]
Kod: Tümünü seç
>>> liste1 = ['index0', 1, 2.1]
>>> liste1
['index0', 1, 2.1]
>>> liste1[0]
'index0'
>>> liste1[1]
1
>>> liste1[2]
2.1
>>> liste1[-1]
2.1
>>> liste1[-2]
1
Concatenation - Birleştirme
Kod: Tümünü seç
[b][b]>>> liste1 = [10,11,12]
>>> len(liste1)
3
>>> liste1 + liste1
[10, 11, 12, 10, 11, 12][/b][/b]
Kod: Tümünü seç
[b]>>> liste2 * 3
[10, 11, 12, 10, 11, 12, 10, 11, 12]
>>> [10] * 3
[10, 10, 10][/b]
list.append ()
append () yöntemi listenin sonuna bir öğe ekler.
Kod: Tümünü seç
>>> liste3 = [1,2]
>>> liste3.append('test')
>>> liste3
[1, 2, 'test']
>>> liste3.append(3)
>>> liste3
[1, 2, 'test', 3]
Aynı şekilde append () bir öğe ekler, expand () çok sayıda öğe ekler.
Kod: Tümünü seç
>>> liste4 = ['a','b']
>>> liste4
['a', 'b']
>>> liste4.extend([1,2,3])
>>> liste4
['a', 'b', 1, 2, 3]
list.insert () yöntemi belirli bir dizine bir dizin ekler; burada, ilk argüman dizin numarası ve ikinci argüman buraya ne eklenir. Burada lister [1] 'index1' dizesini ekliyoruz.
Kod: Tümünü seç
>>> liste5
[1, 2, 3]
>>> liste5.insert(1, 'index1')
>>> liste5
[1, 'index1', 2, 3]
index () yöntemi listedeki bir şeyin argümanını alır ve dizin numarasını geri verir.
Kod: Tümünü seç
>>> liste6 = ['a','b','c']
>>> liste6
['a', 'b', 'c']
>>> liste6.index('b')
1
index () yöntemi listedeki bir şeyin argümanını alır ve dizin numarasını geri verir.
Kod: Tümünü seç
>>> liste6 = ['a','b','c']
>>> liste6
['a', 'b', 'c']
>>> liste6.index('b')
1
Yöntem count (), bağımsız değişkeninin gerçekleşme sayısını verir.
Kod: Tümünü seç
>>> liste7 = list('tester')
>>> liste7
['t', 'e', 's', 't', 'e', 'r']
>>> liste7.count('t')
2
>>> liste7.count('e')
2
>>> liste7.count('r')
1
>>> liste7.count('z')
0
method sort (), dizinleri sırayla sıralar.
Kod: Tümünü seç
>>> liste8 = list('tester')
>>> liste8
['t', 'e', 's', 't', 'e', 'r']
>>> liste8.sort()
>>> liste8
['e', 'e', 'r', 's', 't', 't']
reverse () yöntemi listenin sırasını tersine çevirir.
Kod: Tümünü seç
>>> liste9 = list('tester')
>>> liste9
['t', 'e', 's', 't', 'e', 'r']
>>> liste9.reverse()
>>> liste9
['r', 'e', 't', 's', 'e', 't']