Lesson 18 of 34

Tuples: மாற்ற முடியாத list

7 min 20 XP

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

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).

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.

Challenge

+20 XP

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

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