tr_sehirler = ['adana', 'ankara', 'istanbul']
print(tr_sehirler[0])
tr_sehirler[1] = 'balikesir'When you create a list like this, the order is preserved.
Nested Lists
list1 = ['a', 'b', 'c']
list2 = ['z', 'y', 'x']
nested_list = [list1, list2]When you print nested_list[0], it will print all list1
When you print nested_list[0][1], it will print ‘b’
Functions
List Manipulation
append()
To add an item to the end of the list, you use this function.
tr_sehirler.append('denizli')insert()
Insert an item to a specified location
tr_sehirler.insert(0,'zonguldak') # insert as the first of the list tr_sehirler.insert(1,'adiyaman') # insert as the second of the listextend()
Add another list to the existing list
tr_sehirler.extend(['bursa', 'burdur', 'tokat'])sum()
Sum of all the numbers in a list
random.choice(list)
Choose a random item from a given list
Link to originallist()
Turns a string into a list by individual characters
word = pencil my_list = list(word) # ['p','e',....]join()
It is used to join stuff. It can also be used to convert strings into text
xs = ['1', '2', '3'] s = ''.join(xs)count()
Count how many times that item appears in the a list
points = [1,1,2,2,3,3,3,3] x = points.count(3) # x is 4index()
Give the position of an item in a list
Link to originalCircular transclusion detected: Python/Basics/Built-in-Functions