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)
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)
In [5]:
# indexing and slicing
In [7]:
print my_weeks[0]
my_weeks[0]="sunday"
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
In [10]:
a,b,c,d,e,f = my_weeks
In [11]:
a,b,c,d,e,f,g,h = my_weeks
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)]
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)])
In [19]:
#my_students = ['manu','suresh','kishore','ashok','ashish','sri']
#my_subjects = ['python','django','dockers','kubernates','chef','salt']
my_students.sort()
print my_students
In [20]:
print my_subjects
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)])
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
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)
In [28]:
# anticlimax
my_exams.sort()
In [29]:
print my_exams
In [30]:
# ashish want to give ansible
my_exams[0]=('asish','ansible')
print my_exams
In [31]:
print dir(my_weeks)
In [ ]:
# my_weeks.count
# my_weeks.index