Popular Posts

Tuesday, August 25, 2020

Python Beginner: Tuples

 Hello, developer!


Today, we will learn the Tuples. A tuple is a set of unchangeable data. It is similar with lists but we can't modify item in the tuple. A tuple declared with ( ). I showed some examples of tuples as following.


Tuple examples

- Mathematical constants (3.141592, 2.718)  

- Root constants (1, 1.414, 1.732, 2, 2.236) 

- Product prices ( 5, 10, 15, 30, 50, 100)


If you tried to modify value in the tuples, Python shows you an error. But you can modify the value in the list as following codes exercise.

coordinates = (4, 5)
coordinates2 = [(4,5), (6,7), (80,34)]
coordinates2[1] = 10
print(coordinates)
print(coordinates2)

Can you understand the difference between tuples and lists? Simply we can say a tuple is unchangeable data set and a list is changeable data set. We can utilize tuples in the fixed values - constants in math, science or measurements in the world like height, distance, length or product prices, etc.


Are you clear on tuples? Great! Congratulations, developer!

See you on next post! 😊





1 comment:

  1. In Chemin de Fer, the participant providing to guess probably the most becomes the Banker and is responsible for dealing the cards. Once bets are placed, two cards are dealt to each the 원 엑스 벳 Player and the Banker. Let your creativity run free and arrange original tables with the Mille Nuits Infinite assortment.

    ReplyDelete

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...