In [ ]:
# tuples is readonly representation of lists
# states in a country,days of week,defaults values.

In [2]:
my_weeks = ('sun','mon','tue','wed','thu','fri','sat')
print  my_weeks,type(my_weeks)


 ('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat') <type 'tuple'>

In [4]:
# creating an empty tuple.
my_empty = ()
print my_empty,type(my_empty)

# creating a empty tuple.
my_empty = tuple()
print my_empty,type(my_empty)


() <type 'tuple'>
() <type 'tuple'>

In [5]:
# indexing and slicing

In [7]:
print my_weeks[0]
my_weeks[0]="sunday"


sun
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-6b59fc8df626> in <module>()
      1 print my_weeks[0]
----> 2 my_weeks[0]="sunday"

TypeError: 'tuple' object does not support item assignment

In [9]:
# packing and unpacking
# lists and tuples are packing.
my_weeks = ('sun','mon','tue','wed','thu','fri','sat')
# a = my_weeks[0]
a,b,c,d,e,f,g = my_weeks
print a,b,c,d,e,f,g


sun mon tue wed thu fri sat

In [10]:
a,b,c,d,e,f = my_weeks


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-629dcf0e9710> in <module>()
----> 1 a,b,c,d,e,f = my_weeks

ValueError: too many values to unpack

In [11]:
a,b,c,d,e,f,g,h = my_weeks


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-76ae4d320430> in <module>()
----> 1 a,b,c,d,e,f,g,h = my_weeks

ValueError: need more than 7 values to unpack

In [12]:
# lists and tuples

In [13]:
my_students = ['manu','suresh','kishore','ashok','ashish','sri']
my_subjects = ['python','django','dockers','kubernates','chef','salt']

In [17]:
name='manu'
print name
print name in my_students
print my_students.index(name)
print my_subjects[my_students.index(name)]


manu
True
0
python

In [18]:
name = raw_input("please enter your name:")
if name in my_students:
    print "{} is going to give exam {}".format(name, my_subjects[my_students.index(name)])


please enter your name:manu
manu is going to give exam python

In [19]:
#my_students = ['manu','suresh','kishore','ashok','ashish','sri']
#my_subjects = ['python','django','dockers','kubernates','chef','salt']

my_students.sort()
print my_students


['ashish', 'ashok', 'kishore', 'manu', 'sri', 'suresh']

In [20]:
print my_subjects


['python', 'django', 'dockers', 'kubernates', 'chef', 'salt']

In [21]:
name = raw_input("please enter your name:")
if name in my_students:
    print "{} is going to give exam {}".format(name, my_subjects[my_students.index(name)])


please enter your name:manu
manu is going to give exam kubernates

In [22]:
# list of tuples
#my_students = ['manu','suresh','kishore','ashok','ashish','sri']
#my_subjects = ['python','django','dockers','kubernates','chef','salt']
my_exams = [('manu','python'),
            ('suresh','django'),
            ('kishore','dockers'),
            ('ashok','kubernates'),
            ('ashish','chef'),
            ('sri','salt')]

In [23]:
print my_exams


[('manu', 'python'), ('suresh', 'django'), ('kishore', 'dockers'), ('ashok', 'kubernates'), ('ashish', 'chef'), ('sri', 'salt')]

In [27]:
name = raw_input("please enter your name:")
for student,exam in my_exams:
    if name == student:
        print "{} is going to give exam {}".format(student,exam)


please enter your name:sri
sri is going to give exam salt

In [28]:
# anticlimax
my_exams.sort()

In [29]:
print my_exams


[('ashish', 'chef'), ('ashok', 'kubernates'), ('kishore', 'dockers'), ('manu', 'python'), ('sri', 'salt'), ('suresh', 'django')]

In [30]:
# ashish want to give ansible
my_exams[0]=('asish','ansible')
print my_exams


[('asish', 'ansible'), ('ashok', 'kubernates'), ('kishore', 'dockers'), ('manu', 'python'), ('sri', 'salt'), ('suresh', 'django')]

In [31]:
print dir(my_weeks)


['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']

In [ ]:
# my_weeks.count
# my_weeks.index