Lesson 18 of 34

Tuples: மாற்ற முடியாத listTuples: Lists that Don't Change

7 min 20 XP

tuple என்பது ( ) அடைப்புக்குறியில் எழுதப்படும் list போன்றது. ஆனால் உருவாக்கிய பிறகு மாற்ற முடியாது. மாறக்கூடாத தகவல்களுக்கு (பிறந்த தேதி, GPS இடம்) இது சிறந்தது.

A tuple is like a list written with ( ), but it cannot be changed after it's created. Great for data that shouldn't change, like a date of birth or a GPS location.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Unpacking: tuple-ன் மதிப்புகளை ஒரே வரியில் பல variables-க்கு கொடுக்கலாம். இதைக் கொண்டு இரண்டு variables-ஐ எளிதாக மாற்றலாம் (swap).

Unpacking: give a tuple's values to several variables in one line. It also makes swapping two variables easy.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

ஒரே ஒரு மதிப்புள்ள tuple-க்கு கமா வேண்டும்: (5,). (5) என்பது வெறும் எண் 5.

A one-item tuple needs a comma: (5,). Plain (5) is just the number 5.

Challenge

+20 XP

point = (3, 4). அதை x, y என unpack செய்யுங்கள். முதல் வரியில் x y (இடையில் space) print செய்து, இரண்டாவது வரியில் x*x + y*y மதிப்பை print செய்யுங்கள்.

point = (3, 4). Unpack it into x and y. Print x and y on the first line (separated by a space), then x*x + y*y on the second line.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.