Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 4

355 bytes added, 09:32, 14 June 2017
PART 1 - Tuples
:'''Perform the Following Steps:'''
:#Start by opening the Launch your ipython3 shell:<source>ipythonipython3</source>Let's create two tuples, so we can learn how to use them and learn how they differ from lists.<br><br>:#Create two tuples to experiment withIssue the following:<source>
t1 = ('Prime', 'Ix', 'Secundus', 'Caladan')
t2 = (1, 2, 3, 4, 5, 6)
</source>
:#Values from a tuple can be retreived retrieved in the same way as a list.For example, issue the following:<source>
t1[0]
t2[2:4]
</source>
:#Or You can also check if to see whether a value exists inside a tupleor not.To demonstrate, issue the following:<source>
'Ix' in t1
'Geidi' in t1
</source>Let's now see how a tuple differs from a list. We will now create a list and note the difference between them.:#Issue the following to create a list:<source><br><br> </source>
:#Try changing a tuple value.<source>
t2[1] = 10
13,420
edits