Lesson 18 of 34

Tuples: न बदलने वाली Lists

7 min 20 XP

tuple, ( ) से लिखी list जैसा है, पर बनने के बाद बदला नहीं जा सकता। जन्मतिथि या 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 की अदला-बदली भी आसान हो जाती है।

Example: edit me and press Run

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

एक item वाले tuple में comma चाहिए: (5,)। सिर्फ़ (5) तो बस संख्या 5 है।

Challenge

+20 XP

point = (3, 4)। इसे x और y में unpack करें। पहली लाइन में x और y (space से अलग), दूसरी लाइन में x*x + y*y print करें।

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