Uman Sheikh’s Post

🚨 𝗣𝘆𝘁𝗵𝗼𝗻 𝗙𝘂𝗻 𝗙𝗮𝗰𝘁 𝗗𝗮𝘆 𝟱 A tuple is 𝘪𝘮𝘮𝘶𝘵𝘢𝘣𝘭𝘦… right? 👀 Then explain THIS 😳 𝚝 = ([𝟷, 𝟸, 𝟹], [𝟺, 𝟻]) 𝚝[𝟶].𝚊𝚙𝚙𝚎𝚗𝚍(𝟿𝟿) 𝚙𝚛𝚒𝚗𝚝(𝚝) 𝗘𝘅𝗽𝗲𝗰𝘁𝗲𝗱: Error because tuple is immutable 𝗔𝗰𝘁𝘂𝗮𝗹 𝗢𝘂𝘁𝗽𝘂𝘁: ([𝟷, 𝟸, 𝟹, 𝟿𝟿], [𝟺, 𝟻]) 𝗪𝗵𝗮𝘁’𝘀 𝗴𝗼𝗶𝗻𝗴 𝗼𝗻? Yes, tuples are immutable… BUT: They only protect the 𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲, not the 𝗰𝗼𝗻𝘁𝗲𝗻𝘁𝘀 So: • You can’t change the tuple itself  • But you can modify objects inside it In this case: • The list inside the tuple is still mutable • So .append() works perfectly fine 𝗦𝗶𝗺𝗽𝗹𝗲 𝗯𝗿𝗲𝗮𝗸𝗱𝗼𝘄𝗻: Tuple = locked container  But items inside = free to move 𝗪𝗵𝘆 𝘁𝗵𝗶𝘀 𝗺𝗮𝘁𝘁𝗲𝗿𝘀: • Can lead to unexpected data changes • Important in nested data structures • Common confusion in interviews 😅 𝗣𝘆𝘁𝗵𝗼𝗻 𝗯𝗲 𝗹𝗶𝗸𝗲: “Main bahar se strict hoon… andar se flexible” 📌 𝗗𝗮𝘆 𝟲 𝗰𝗼𝗺𝗶𝗻𝗴 𝘁𝗼𝗺𝗼𝗿𝗿𝗼𝘄: A clean Python trick that replaces 3 lines with just 1 😎 Follow for more “yeh allowed hai??” moments 😄 #Python #Programming #Developers #Coding #AI #DataScience #LearnPython

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories