len()
function[]
)[]
)
0
in Python, other programming languages begin
at 1
listExample1 = ["4061CEM", "Programming", "Algorithms"]
listExample2 = [4061, "Programming and Algorithms", True,
["Dr Ian Cornelius", "Mr Terry Richards"]]
listExample1[1] = Programming
listExample1[1].upper() = PROGRAMMING
listExample2[3][1] = Mr Terry Richards
-1
will refer to the last item and
-2
the second to last item etc.listExample1[-1] = Algorithms
listExample1[-2] = Programming
slice
:
”) between the two numbers1:3
represents begin at index
1
and go up to index 3
listExample1[1:3] = [‘Programming and Algorithms’, True]
listExample1[:3] = [4061, ‘Programming and Algorithms’, True]
listExample1[2:] = [True, ‘Dr Ian Cornelius’]
insert()
functionlistExample1 = [‘4061CEM’, ‘Programming’, ‘Algorithms’, ‘Dr Ian Cornelius’]
listExample1 = [‘4061CEM’, ‘Dr Ian Cornelius’, ‘Programming’, ‘Algorithms’]
append()
functionlistExample1 = [‘4061CEM’, ‘Programming’, ‘Algorithms’, ‘Mr Terry Richards’]
remove()
functionlistExample1 = [‘4061CEM’, ‘Algorithms’]
pop()
function
listExample1 = [‘4061CEM’, ‘Algorithms’]
[]
) and using the
del
keywordlistExample1 = [‘4061CEM’, ‘Algorithms’]
clear()
function[]
)listExample1 = []
+
operatorlistExample1 = ["4061CEM", "Programming and Algorithms 1", "Dr Ian Cornelius"]
listExample2 = ["4059CEM", "Legal and Ethical Foundations", "Mr Terry Richards"]
mergedListExample1 = [‘4061CEM’, ‘Programming and Algorithms 1’, ‘Dr Ian Cornelius’, ‘4059CEM’, ‘Legal and Ethical Foundations’, ‘Mr Terry Richards’]
extend()
functionlistExample1 = ["4061CEM", "Programming and Algorithms 1", "Dr Ian Cornelius"]
listExample2 = ["4059CEM", "Legal and Ethical Foundations", "Mr Terry Richards"]
listExample1 = [‘4061CEM’, ‘Programming and Algorithms 1’, ‘Dr Ian Cornelius’, ‘4059CEM’, ‘Legal and Ethical Foundations’, ‘Mr Terry Richards’]
list2 = list1
is incorrect
list1
and not an actual copy; therefore any changes made
in list1
will occur in list2
copy()
function or the list()
constructor itselfcopyListExample1 = [‘4061CEM’, ‘Programming’, ‘Algorithms’]
copyListExample2 = [‘4061CEM’, ‘Programming’, ‘Algorithms’]
len()
function()
)tupleExample1 = (‘4061CEM’, ‘Programming’, ‘Algorithms’)
tupleExample2 = (‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ’ ‘, ’4’, ‘0’, ‘6’, ‘1’, ‘C’, ‘E’, ‘M’)
tupleExample1 = ("4061CEM", "Programming", "Algorithms")
tupleExample2 = (4061, "Programming and Algorithms", True,
("Dr Ian Cornelius", "Mr Terry Richards"))
tupleExample1 = (‘4061CEM’, ‘Programming’, ‘Algorithms’)
tupleExample2 = (4061, ‘Programming and Algorithms’, True, (‘Dr Ian Cornelius’, ‘Mr Terry Richards’))
[]
)
0
in Python, other programming languages
begin at 1
tupleExample1[1] = Programming
tupleExample1[2] = Algorithms
-1
will refer to the last item and
-2
the second to last item etc.tupleExample1[-1] = Algorithms
tupleExample1[-2] = Programming
slice
:
”) between the two numbers1:3
represents begin at index
1
and go up to index 3
tupleExample1[1:3] = (‘Programming and Algorithms’, True)
tupleExample1[:3] = (4061, ‘Programming and Algorithms’, True)
tupleExample1[2:] = (True, ‘Dr Ian Cornelius’)
[Before] tupleExample1 = (‘4061CEM’, ‘Programming’, ‘Algorithms’)
[After] tupleExample1 = (‘4061CEM’, ‘Programming’, ‘Algorithms’, ‘Ian Cornelius’)
del
keyword+
”)
operatortupleExample1 = ("4061CEM", "Programming and Algorithms 1", "Dr Ian Cornelius")
tupleExample2 = ("4059CEM", "Legal and Ethical Foundations", "Mr Terry Richards")
mergedTupleExample1 = (‘4061CEM’, ‘Programming and Algorithms 1’, ‘Dr Ian Cornelius’, ‘4059CEM’, ‘Legal and Ethical Foundations’, ‘Mr Terry Richards’)
*
”) operatortupleExample2 = (‘4061CEM’, ‘Programming’, ‘Algorithms’, ‘4061CEM’, ‘Programming’, ‘Algorithms’, ‘4061CEM’, ‘Programming’, ‘Algorithms’)
module_code = 4061CEM
title1 = Programming
title2 = Algorithms
*
to the variable name will
assign remaining items in the tuple to a listmodule_code = 4061CEM
title = [‘Programming’, ‘Algorithms’]
*
to a variable that is not
last, then Python will assign values to a list for that
variable until the number of values left match the number of
variables leftmodule_code = 4061CEM
*title = [‘Programming’, ‘Algorithms’, ‘1’]
leader = Dr Ian Cornelius
running = True
count()
method will return the number
of times a specified value will occur in the list or
tuplelistExample1.count(‘Algorithms’) = 2
index()
method will search the list for
a specified value and return its index in the list or
tupletupleExample1.index(“Programming”) = 1