Aliasing TRB CSI › Python Programming › aliasing

Aliasing

Aliasing என்பது ஒரே object-ஐ இரண்டு அல்லது அதற்கு மேற்பட்ட variables reference செய்வது. Simple definition: When two or more variables refer to the same object, it is called aliasing.

Premium — locked Advanced 17 min 131 cards 35 programs 8 MCQs v4
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

ALIASING IN PYTHON…

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

Aliasing என்பது ஒரே object-ஐ இரண்டு அல்லது அதற்கு மேற்பட்ட variables re……

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

இங்கே a மற்றும் b இரண்டு different ……

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

ஒரு classroom-ல் ஒரு student இருக்கிறார் என்று எடுத்துக்கொள்ளுங்கள். அந்த student-ஐ: Nagarajan Kalviyogi என்ற……

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

a = [10, 20, 30] Memory concept: a --------> [10, 20, 30] Next: b……

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

Aliasing-க்கு separate keywor……

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

Mutable object-ல் இதன் effect……

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

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock

இங்கே output same என்பதனால் ம……

Premium This card is part of the premium lesson. Unlock
Important
முக்கியம்

a மற்றும் b same object-ஐ reference செய்கின்றன. ALIASING-ன் MAIN……

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

நாம் b-ஐ மட்டும் change செய்தோம். அப்படியிருக்க ……

Premium This card is part of the premium lesson. Unlock

Why? b.append(30) same list o……

Premium This card is part of the premium lesson. Unlock

b மூலம் remove செய்தாலும் a ம……

Premium This card is part of the premium lesson. Unlock

Again: same object ALIASING vs COPYIN……

Premium This card is part of the premium lesson. Unlock

இதில்: a ----\ ---> One List ……

Premium This card is part of the premium lesson. Unlock

இதில்: a ---> [10, 20, 30] b --->……

Premium This card is part of the premium lesson. Unlock

Python-ல் இரண்டு variables same object-ஐ……

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

a = [10, 20]…

Premium This card is part of the premium lesson. Unlock

Because: a and b refer to same object == vs is இது மிகவும் முக்கியமான interview/TRB conce……

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

a = [10, 20] b = [10, 20]…

Premium This card is part of the premium lesson. Unlock

Why? Contents same: [10,20] == [10,20] அதனால்: True ஆ……

Premium This card is part of the premium lesson. Unlock

Because: Same values + Same o……

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

Case 1 - Aliasing a = [10, 20] b = a a -------\ ---> [10,20] b -------/ Therefore: a is b -> True a == b -> T……

Premium This card is part of the premium lesson. Unlock

Function உள்ளே: x and outside: a t……

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

a ----\ ---> [10,20] x ----/ Then: x.append(30) same object becomes: [10,20……

Premium This card is part of the premium lesson. Unlock

ஏன்? Initially: a ----\ ---> [10,20] x ----/ Inside function: x = [100, 200] இப்போது: a ---> [10,20] x ---> [……

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

Output conceptually: {1, 2, 3, 4} Again: same set object ALIASING ……

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

a மற்றும் b same string object-ஐ refer செய்யலாம். ஆனால் string immutable. So: b[0] = "J" செய்ய முடியாது. Ther……

Premium This card is part of the premium lesson. Unlock

இப்போது: a[0][0] = 100…

Premium This card is part of the premium lesson. Unlock

Why all three changed? Because: row object ஒன……

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

a[0] ---\ a[1] ----> [0,0] a[2] ---/ இதுவும் aliasing. VERY IMPORTANT PYTHON ……

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

a = [[0] * 3] * 3 a[0][0] = 1…

Premium This card is part of the premium lesson. Unlock

ஏன்? Same inner list repeated……

Premium This card is part of the premium lesson. Unlock

இங்கே each iteration new inner list create ……

Premium This card is part of the premium lesson. Unlock

But inner objects shared.…

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

a ---> [ ---- , ---- ] | | v v [1,2] [3,4……

Premium This card is part of the premium lesson. Unlock

Because inner list is aliased……

Premium This card is part of the premium lesson. Unlock

deepcopy() nested mutable obj……

Premium This card is part of the premium lesson. Unlock
Comparison
Aliasing vs Shallow Copy vs Deep Copy
Important

Aliasing பற்றி நினைவில் வைத்திருக்க வேண்டிய main points: Aliasing means multiple variables refer to the same ……

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

Wrong assumption: a = [10, 20] b = a Student th……

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

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

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

Confusing: == with: is…

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

== -> same value? is -> same ……

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

a = [[0, 0]] * 3 இது three independent inner l……

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

Aliasing: ONE OBJECT MANY NAM……

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

a ----\ ---> Same Object b --……

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

= -> may create alias/reference == -> compare v……

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

What is aliasing?…

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

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

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

a = [10, 20] b = a print(a is……

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

a = [10, 20] b = [10, 20] pri……

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

Which statement creates an al……

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

What is aliasing in Python? Aliasing occurs when multiple variables reference the same object. Why is aliasin……

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

What does aliasing mean?…

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

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

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

Which operator checks object ……

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

Which checks value equality?…

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

Which creates a shallow copy ……

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

Aliasing problems are especia……

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

Predict the output. 1. a = [10, 20] b = a b[0] = 50 print(a) 2. a = [1, 2, 3] b = a.copy() b[0] = 100 print(a……

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

Aliasing: a = [10, 20] b = a Memory: a ----\ ---> [10,20] b ----/ Therefor……

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

b = a -> alias b = a.copy() -> shallow copy b……

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

Aliasing என்பது Python-ல் இரண்டு அல்லது அதற்கு மேற்பட்ட variables ஒரே object-ஐ reference செய்வது. குறிப்பாக m……

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