Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: list-in-python

Web Development and Design | Tutorial for Java, PHP, HTML, Javascript: list-in-python
Showing posts with label list-in-python. Show all posts
Showing posts with label list-in-python. Show all posts

Python Tuples

Python Tuples




Tuples

A tuple is like a list, except you can't change the values in a tuple once it's defined. Tuples are good foo storing information that shouldn't be changed throughout the life of a program. Tuples are designated by parenthesis instead of square brackets. (You can overwrite an entire tuple, but you can't change the individual elements in a tuple.)

#Defining a tuple
dimensions = (800, 600)
#looping through a tuple 
for dimension in dimensions:
	print (dimension)
#Overwriting a tuple
dimensions = (800, 600)
print(dimensions)

dimensions = (1200, 900)
print(dimensions)

Screenshot