In [3]:
list = [1,2,3,]

In [4]:
len(list)


Out[4]:
3

In [1]:
list = ['string data type', 23.23, 100]

In [2]:
len(list)


Out[2]:
3

In [3]:
list2 = ['one', 'a', 'twenty']

In [4]:
list2[0] #indexing


Out[4]:
'one'

In [5]:
list2[::1] #slicing


Out[5]:
['one', 'a', 'twenty']

In [6]:
list2[1::] #more slicing


Out[6]:
['a', 'twenty']

In [7]:
list2[0:2:1] #even more slicing


Out[7]:
['one', 'a']

In [10]:
list + list2 #concatination


Out[10]:
['string data type', 23.23, 100, 'one', 'a', 'twenty']

In [11]:
(list + list2)[3:5:1] #concatination with slicing


Out[11]:
['one', 'a']

In [15]:
(list + list2)[3]#concatination and indexing


Out[15]:
'one'

In [16]:
list3 = list + list2

In [17]:
list3


Out[17]:
['string data type', 23.23, 100, 'one', 'a', 'twenty']

In [20]:
list3.append('another entry')

In [22]:
len(list3)


Out[22]:
8

In [31]:
list3[7] = 'CAPITALISED'

In [32]:
list3


Out[32]:
['string data type',
 23.23,
 100,
 'one',
 'a',
 'twenty',
 'another entry',
 'CAPITALISED']

In [33]:
list3.remove('another entry')

In [34]:
list3


Out[34]:
['string data type', 23.23, 100, 'one', 'a', 'twenty', 'CAPITALISED']

In [35]:
list3.reverse()

In [36]:
list3


Out[36]:
['CAPITALISED', 'twenty', 'a', 'one', 100, 23.23, 'string data type']

In [39]:
list3.count(100)


Out[39]:
1

In [42]:
list3.count('a') #count the quantity of specified items in the current list


Out[42]:
1

In [43]:
list4 = ['a','a',2,'a','two','a',2,'a','counters','counters','counters']

In [44]:
list4


Out[44]:
['a', 'a', 2, 'a', 'two', 'a', 2, 'a', 'counters', 'counters', 'counters']

In [46]:
c_one = list4.count('a') #Allocate data to variables
c_two = list4.count(2)
c_three = list4.count('counters')
print(c_one, c_two, c_three) #print them for the counting exercise


5 2 3

In [48]:
list4.pop()#removes last index and returns it.


Out[48]:
'counters'

In [51]:
mypopped = list4.pop()

In [52]:
mypopped


Out[52]:
'a'

In [53]:
list4


Out[53]:
['a', 'a', 2, 'a', 'two', 'a', 2]

In [60]:
list4.insert(1, 2)

In [62]:
list4.pop(3) #popping from the index location


Out[62]:
'a'

In [63]:
list4


Out[63]:
['a', 2, 'a', 'a', 'two', 'a', 2, 'a']

In [64]:
newlist = ['a','d','x','delta']
numlist = [1287, 89765, 354, 23, 6890, 457, 9, 0, 3, 2, 1]

In [65]:
newlist.sort()

In [66]:
newlist


Out[66]:
['a', 'd', 'delta', 'x']

In [67]:
numlist.sort()

In [68]:
numlist


Out[68]:
[0, 1, 2, 3, 9, 23, 354, 457, 1287, 6890, 89765]

In [69]:
numlistsorted = numlist.sort()

In [70]:
type(numlist)


Out[70]:
list

In [72]:
type(numlistsorted) #no type as the method has not been called


Out[72]:
NoneType

In [73]:
None # Is very useful for a method or function which return nothing (helper methods maybe? - look up uses).

In [79]:
numlist.sort()
mysortednumlist = numlist # The proper way to do it, call the method, add the result to the malloc (variable).

In [81]:
mysortednumlist # Call the variable


Out[81]:
[0, 1, 2, 3, 9, 23, 354, 457, 1287, 6890, 89765]

In [82]:
numlist.reverse()

In [83]:
numlist


Out[83]:
[89765, 6890, 1287, 457, 354, 23, 9, 3, 2, 1, 0]

In [ ]: