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 কয়েকটি variable-এ দিন। এতে দুটি variable 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 print করুন (space দিয়ে আলাদা), তারপর দ্বিতীয় লাইনে x*x + y*y।

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