Lesson 18 of 34

Tuples: മാറാത്ത Lists

7 min 20 XP

Tuple ( ) ഉപയോഗിച്ച് എഴുതുന്ന list പോലെയാണ്, പക്ഷേ ഉണ്ടാക്കിയ ശേഷം മാറ്റാനാവില്ല. ജനനത്തീയതി, GPS location പോലെ മാറാത്ത data-ക്ക് ഉത്തമം.

Example: edit me and press Run

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

Unpacking: ഒരു വരിയിൽ tuple-ന്റെ values പല 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.

ഒരു item ഉള്ള tuple-ന് comma വേണം: (5,). വെറും (5) എന്നാൽ സംഖ്യ 5 മാത്രം.

Challenge

+20 XP

point = (3, 4). അത് x, y ആയി unpack ചെയ്യൂ. ആദ്യ വരിയിൽ x, y (space കൊണ്ട് വേർതിരിച്ച്) print ചെയ്യൂ, പിന്നെ രണ്ടാം വരിയിൽ x*x + y*y.

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