Back

'Modifying' and examining tuples

Use this for the questions that follow:

monsters=('goblin', 'orc', 'evil pixie', 'ogre', 'firedog', 'mummy', 'witch')

Predict what will happen when you try to do each of the following using the tuple above in a Python program. When you have predicted what will happen for every question, run the code and compare your prediction with the results. Try to explain any results that differ from your predictions, using the Internet to help you if necessary.

Q1.

monsters.append("genie")
print (monsters)

Q2.

monsters.remove("evil pixie")
print(monsters)

Q3.  

print (monsters.index('mummy'))

Q4. 

print (monsters.index('goblin'))

Q5. 

print ("orc" in monsters)

Q6. 

print ("undead" in monsters)

Q7. 

print (monsters*2)

Q8. 

monsters2 = monsters + "undead"
print (monsters2)

Q9.

monsters_temp = ('undead')
monsters2 = monsters + monsters_temp
print (monsters2)

Q10.

monsters_temp = ('genie',)
monsters2 = monsters + monsters_temp
print (monsters2)

Q11.

monsters_temp = ('zombie',)
monsters2 = monsters + monsters_temp
print (monsters2)
print (len(monsters2))

Back