In [3]:
list = [1,2,3,]
In [4]:
len(list)
Out[4]:
In [1]:
list = ['string data type', 23.23, 100]
In [2]:
len(list)
Out[2]:
In [3]:
list2 = ['one', 'a', 'twenty']
In [4]:
list2[0] #indexing
Out[4]:
In [5]:
list2[::1] #slicing
Out[5]:
In [6]:
list2[1::] #more slicing
Out[6]:
In [7]:
list2[0:2:1] #even more slicing
Out[7]:
In [10]:
list + list2 #concatination
Out[10]:
In [11]:
(list + list2)[3:5:1] #concatination with slicing
Out[11]:
In [15]:
(list + list2)[3]#concatination and indexing
Out[15]:
In [16]:
list3 = list + list2
In [17]:
list3
Out[17]:
In [20]:
list3.append('another entry')
In [22]:
len(list3)
Out[22]:
In [31]:
list3[7] = 'CAPITALISED'
In [32]:
list3
Out[32]:
In [33]:
list3.remove('another entry')
In [34]:
list3
Out[34]:
In [35]:
list3.reverse()
In [36]:
list3
Out[36]:
In [39]:
list3.count(100)
Out[39]:
In [42]:
list3.count('a') #count the quantity of specified items in the current list
Out[42]:
In [43]:
list4 = ['a','a',2,'a','two','a',2,'a','counters','counters','counters']
In [44]:
list4
Out[44]:
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
In [48]:
list4.pop()#removes last index and returns it.
Out[48]:
In [51]:
mypopped = list4.pop()
In [52]:
mypopped
Out[52]:
In [53]:
list4
Out[53]:
In [60]:
list4.insert(1, 2)
In [62]:
list4.pop(3) #popping from the index location
Out[62]:
In [63]:
list4
Out[63]:
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]:
In [67]:
numlist.sort()
In [68]:
numlist
Out[68]:
In [69]:
numlistsorted = numlist.sort()
In [70]:
type(numlist)
Out[70]:
In [72]:
type(numlistsorted) #no type as the method has not been called
Out[72]:
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]:
In [82]:
numlist.reverse()
In [83]:
numlist
Out[83]:
In [ ]: