Saturday, February 17, 2018

Tuples

A tuple looks like a list but instead of using square brackets we use parentheses:
myTuple = ('Real Madrid', 'FC Barcelona')
print(myTuple)

Output:
Real Madrid, FC Barcelona

note: Tuples values cannot be modify like list i.e.

myTuple[0] = 'Arsenal

Output: 
if we run this code an Error will be raised.



Print all elements:
for i in myTuple:
       print(i)

Output:
Real Madrid, FC Barcelona

Tuples cannot be modify but we can assign a new value to a variable holding a tuple.
myTeam = ('Real Madrid', 'FC Barcelona')

Could be modify:
myTeam = ('FC Barcelona', 'Arsenal')





No comments:

Post a Comment