mutability TRB CSI › Python Programming › mutability

mutability

Mutability என்பது ஒரு object create செய்யப்பட்ட பிறகு, அதன் value அல்லது contents-ஐ same object-ஐ வைத்துக்கொண்டே மாற்ற முடியும் என்ற property. Simple definition: An object is mutable if its contents can be changed after creation. Python-ல்…

Premium — locked Advanced 14 min 106 cards 23 programs 7 MCQs v4
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

MUTABILITY IN PYTHON…

Premium This card is part of the premium lesson. Unlock
Definition

Mutability என்பது ஒரு object create செய்யப்பட்ட பிறகு, அதன் value அல்லது contents-ஐ same object-ஐ வைத்துக்கொண……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

ஒரு notebook-ஐ எடுத்துக்கொள்ளுங்கள். அதில்: 10 20 30 என்று எழுதப்பட்டுள்ளது. இப்போது 20-ஐ erase செய்து 200 ……

Premium This card is part of the premium lesson. Unlock
Output
Result

List புதிதாக create செய்யாமல்……

Premium This card is part of the premium lesson. Unlock
Flow

Create List | v [10, 20, 30] | | a[1] =……

Premium This card is part of the premium lesson. Unlock
Explanation

List element modify செய்ய: list_……

Premium This card is part of the premium lesson. Unlock
Explanation

a[1] = 200…

Premium This card is part of the premium lesson. Unlock
Explanation

a = [10, 20, 30] ஒரு list create செய்கிறோம். a[1] = 200 Index 1-ல் ……

Premium This card is part of the premium lesson. Unlock

இதிலிருந்து: List is mutable.…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. ADDING ELEMENTS ALSO SHOWS……

Premium This card is part of the premium lesson. Unlock

a = [10, 20] a.append(30)…

Premium This card is part of the premium lesson. Unlock

Original list content change ……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. REMOVING ELEMENTS…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30] a.remove(20)…

Premium This card is part of the premium lesson. Unlock

இதுவும் mutability.…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. SLICE MODIFICATION…

Premium This card is part of the premium lesson. Unlock

List slice-ஐ கூட modify செய்ய……

Premium This card is part of the premium lesson. Unlock

இதில்: a[1:3] means: 20, 30 அதை: 200, 300 ஆக repl……

Premium This card is part of the premium lesson. Unlock

இங்கே a மற்றும் b இரண்டு completely independent lists அல்ல. இரண்டும் same ……

Premium This card is part of the premium lesson. Unlock
Explanation

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Explanation

b[0] = 100…

Premium This card is part of the premium lesson. Unlock
Program
Because

என்றால் list copy create செய்யவில்லை. b same list object-ஐ reference செய்கிறது. Before: a ----\ ---> [10, 20,……

Premium This card is part of the premium lesson. Unlock

பயன்படுத்தலாம்.…

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Explanation

b[0] = 100…

Premium This card is part of the premium lesson. Unlock

இப்போது: a ---> [10, 20, 30] b ---> [100, 20, 30] Separate outer list objects. MUTABLE vs IMMUTABLE இது மிகவு……

Premium This card is part of the premium lesson. Unlock
Comparison

LIST vs TUPLE List: a = [10, ……

Premium This card is part of the premium lesson. Unlock

Because list is mutable. Tupl……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

TypeError Because tuple is immutable. LIST vs STRING List: ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

TypeError: 'str' object does not support item assignment Because string……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

இதனால் integer mutable என்று அர்த்தம் இல்லை. 10 integer object-ஐ நாம் 20 ஆக modify செய்யவில்லை. Instead: Init……

Premium This card is part of the premium lesson. Unlock
Explanation

a[0] = 100…

Premium This card is part of the premium lesson. Unlock
Explanation

பொதுவாக இரண்டு id values same ……

Premium This card is part of the premium lesson. Unlock
Concept

Before: a ---> [10, 20, 30] After: a ---> [100, 20, 30] Object identity same Contents changed IMMUTABLE STRIN……

Premium This card is part of the premium lesson. Unlock

ஏன்? List mutable. Function-க்கு same list object refer……

Premium This card is part of the premium lesson. Unlock
Dry Run
a = [10, 20]

ஏன்? Function உள்ளே: x = [100, 200] என்பது original list-ஐ mutate செய்யவில்லை. x new list-க்கு reassign செய்ய……

Premium This card is part of the premium lesson. Unlock

copy() outer list-ஐ மட்டும் copy செய்க……

Premium This card is part of the premium lesson. Unlock

ஏனெனில் copy() என்பது shallow copy. SHALLOW COPY Conceptually: a ---> [ inner1 , inner2 ] | | v v [1,2] [3,4]……

Premium This card is part of the premium lesson. Unlock
Important

Mutability பற்றி கண்டிப்பாக நினைவில் வைத்திருக்க வேண்டிய points: List is mutable. Dictionary is mutable. Set ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 1

Many students think: a = [10, 20] b = a mea……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 2

x = 10 x = 20 இதனால் integers mutable என்று……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 3

String: s = "Python" s[0] = "……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error.

Because string is immutable.…

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 4

Tuple: a = (10, 20, 30) a[1] ……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Error

TypeError Tuple is immutable.…

Premium This card is part of the premium lesson. Unlock
Memory Trick

Mutable: L D S List Dictionary Set இவை பொதுவாக modify செய்யக்கூடிய……

Premium This card is part of the premium lesson. Unlock
MCQ

Which of the following is mut……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 2

What is the output? a = [1, 2, 3] b = a b[0] = ……

Premium This card is part of the premium lesson. Unlock
MCQ

Which is immutable?…

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 4

What happens here? s = "Python" s[……

Premium This card is part of the premium lesson. Unlock
Interview Point

What is mutability in Python? Mutability is the ability of……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [1, 2, 3] a[0] = 100 Valid. Is a tuple mutable? No. Tuple is immutable. Difference between mutation and r……

Premium This card is part of the premium lesson. Unlock
MCQ

List is:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which object is immutable?…

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a = [1, 2……

Premium This card is part of the premium lesson. Unlock
MCQ

Which statement about strings……

Premium This card is part of the premium lesson. Unlock
MCQ

x = 20 after x = 10 represent……

Premium This card is part of the premium lesson. Unlock
Practice

Predict the output. 1. a = [10, 20, 30] a[2] = 100 print(a) 2. a = [1, 2] b = a b.append(3) pr……

Premium This card is part of the premium lesson. Unlock
Summary

Mutability Object can be chan……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [10, 20] a[0] = 100 Valid because list is mutable. Mutable objects List Dictionary Set Bytearray Immutabl……

Premium This card is part of the premium lesson. Unlock
Explanation

does not create an independen……

Premium This card is part of the premium lesson. Unlock
Explanation

for a shallow copy.…

Premium This card is part of the premium lesson. Unlock
Explanation
Short description

Mutability என்பது Python object create செய்யப்பட்ட பிறகு அதன் contents-ஐ மாற்ற முடியுமா என்பதைக் குறிக்கும் p……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program