Review Tuples !

my_list = [2,3]
my_tuple = (4,5)
other_tuple = 6,7
my_list[1] = 10
my_list
[2, 10]
my_tuple[1] = 11 #see that tuple cannot be modified
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-ce8c7e54784a> in <module>()
----> 1 my_tuple[1] = 11

TypeError: 'tuple' object does not support item assignment
def sum_product(x, y):
    return (x + y),(x * y)
sp = sum_product(11,12)
sp
(23, 132)
s, p = sum_product(11,12)
s
23
p
132
x,y = 1,2 # multiple assignment is possible both in lists and tuples
x,y = 3,4

Studying Data Science from Scratch by Joel Grus.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s