Python Tuples - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Python Tuples - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Thursday, December 6, 2018

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

 

No comments:

Post a Comment

Post Top Ad