Cloning and Parameters TRB CSI › Python Programming › cloning, and parameters.

Cloning and Parameters

Cloning என்பது ஒரு existing object-ன் contents-ஐ வைத்து ஒரு புதிய independent object உருவாக்குவது. Simple definition: Cloning means creating a separate copy of an object. List example: a = [10, 20, 30] b = a[:] இங்கே b என்பது a-வின் clone.

Premium — locked Intermediate 18 min 177 cards 37 programs 9 MCQs v4
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock
Algorithm

1. CLONING AND PARAMETERS IN ……

Premium This card is part of the premium lesson. Unlock

இந்த இரண்டு concepts Python-ல் குறிப்பாக lists, mut……

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

Cloning என்பது ஒரு existing object-ன் contents-ஐ வைத்து ஒரு புதிய independent object உருவாக்கு……

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

Aliasing-ல்: b = a இதனால்: a ----\ ---> [10, 20, 30] b ----/ ஒரே list object. ஆனால் cloning: b = a[:] இ……

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

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

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

List cloning செய்ய பல ways உள்ளன. Method 1 - Slicing b……

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

b[0] = 100…

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

a = [10, 20, 30] Original list. b = a[:] a-வின் elements c……

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

Again a unaffected.…

Premium This card is part of the premium lesson. Unlock

Memory: a ----\ ---> [10,20] b ----/ If: b.append(30) then: a = [10,20,30] b = [1……

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

== AND is WITH CLONING a = [1……

Premium This card is part of the premium lesson. Unlock

Why? a == b checks values. Values same. So: True But: a is b checks object identi……

Premium This card is part of the premium lesson. Unlock

இதில் problem இல்லை. ஆனால் nested li……

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

b clone என்றால் a ஏன் change ஆனது? Because copy() outer list-ஐ மட்டும் புதியதாக உருவாக்கியது. Inner lists sha……

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

a = [[1, 2], [3, 4]]…

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

b[0][0] = 100…

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

Cloning பற்றி முக்கியமான points: Cloning creates a separate object. b = a cloning அல்ல; அது aliasing. a[:] cl……

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

Wrong assumption: a = [1, 2] b = a இதனை clone என்……

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

Alias: Same list, two names Clone: Same values, two lists Sho……

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

Parameter என்பது function definition-ல் data receive செய்ய பயன்படுத்தப்படும் variable. ……

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

இங்கே: name ஒரு parameter.…

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

ஒரு function ஒரு machine என்ற……

Premium This card is part of the premium lesson. Unlock

அந்த value-ஐ receive செய்யும்……

Premium This card is part of the premium lesson. Unlock
Program
Example
Program
இங்கு
Explanation

Call: square(5) இங்கு: 5 = argument PAR……

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

இங்கே: a, b = parameters Func……

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

Function call: function_name(……

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

add(10, 20)…

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

def add(a, b): Function name: add Parameters: a, b Function……

Premium This card is part of the premium lesson. Unlock
Dry Run
add(10, 20)
Program
Here
Algorithm

1. MULTIPLE PARAMETERS…

Premium This card is part of the premium lesson. Unlock

Parameters: name mark Argumen……

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

1. POSITIONAL PARAMETERS / AR……

Premium This card is part of the premium lesson. Unlock

Python normally arguments-ஐ pos……

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

name = "Ravi" age = 20 POSITION MA……

Premium This card is part of the premium lesson. Unlock

But: subtract(5, 10)…

Premium This card is part of the premium lesson. Unlock

Position changed, result chan……

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

1. KEYWORD ARGUMENTS…

Premium This card is part of the premium lesson. Unlock

Parameter names பயன்படுத்தி a……

Premium This card is part of the premium lesson. Unlock

இங்கே order change ஆனாலும் par……

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

1. DEFAULT PARAMETERS…

Premium This card is part of the premium lesson. Unlock

Parameter-க்கு default value ……

Premium This card is part of the premium lesson. Unlock

Call with value: greet("Ravi")…

Premium This card is part of the premium lesson. Unlock

If: greet() then: name = "Student" If: greet("Ar……

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

1. LIST AS PARAMETER…

Premium This card is part of the premium lesson. Unlock

இது mutability மற்றும் aliasi……

Premium This card is part of the premium lesson. Unlock

add_item(a)…

Premium This card is part of the premium lesson. Unlock

Function call: add_item(a) Functio……

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

a ----\ ---> [10, 20, 30] x ----/ Inside function: x.append(40) same list modify செய்யப்படுகிறது. So:……

Premium This card is part of the premium lesson. Unlock

Because list is mutable. PARA……

Premium This card is part of the premium lesson. Unlock

change(numbers)…

Premium This card is part of the premium lesson. Unlock

Why? Inside function: data = [100, 200] existing list-ஐ modify செய்யவில்லை. Parameter variable data மட்டும் n……

Premium This card is part of the premium lesson. Unlock

Because integer is immutable.……

Premium This card is part of the premium lesson. Unlock

new integer object-க்கு x rea……

Premium This card is part of the premium lesson. Unlock

change(text)…

Premium This card is part of the premium lesson. Unlock

String immutable. Function lo……

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

Mutable Parameter def f(x): x.append(10) List passed: Original may change Immutable Parameter de……

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

1. Positional parameters 2. Default parameters 3. Ke……

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

Unknown number of positional arguments r……

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

*args values tuple-ஆக collect……

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

total(10, 20, 30)…

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

1. **kwargs…

Premium This card is part of the premium lesson. Unlock
Program
Keyword arguments collect செய்ய

**kwargs usually dictionary ஆ……

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

Parameters பற்றி முக்கியமாக நினைவில் கொள்ள: Parameter function definition-ல் இருக்கும். Argument function cal……

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

def add(a, b): print(a + b) a……

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

TypeError Reason: Two required par……

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

def add(a, b): print(a + b) a……

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

Default parameter order: Wrong: def show(a=10, b): print(a, b) SyntaxError……

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

Assuming function always copies a list: def change(x): x.append……

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

Parameter vs Argument: P = Place holder A = Actua……

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

What is cloning?…

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

Which creates an alias? b = a……

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

Which creates a shallow list ……

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

In: def add(x, y): x and y ar……

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

In: add(10, 20) 10 and 20 are:…

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

What is cloning in Python lists? Cloning is the cre……

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

Both refer to same object. Cl……

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

Separate outer list objects. What is a parameter? A parameter is a variable in a fu……

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

Argument: f(10)…

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

Which statement creates a clo……

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

A shallow copy of a nested li……

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

Which module is used for deep……

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

Which one is a parameter? def……

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

Which one is an argument?…

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

1. Predict the output…

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

a = [1, 2, 3] b = a[:] b[0] =……

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

1. Predict the output…

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

a = [1, 2] b = a b.append(3) ……

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

1. Identify parameter and arg……

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

def cube(n): print(n ** 3) cu……

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

1. Predict the output…

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

def add_item(x): x.append(100……

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

1. Predict the output…

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

def change(x): x = x + 5 n = ……

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

Cloning Cloning = separate copy Exa……

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

b = a -> same object b = a.copy() -> separate outer object Nested list: copy() -> shallow copy deepcopy() -> ……

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

Cloning என்பது existing list-ன் contents-ஐ வைத்து separate list object உருவாக்குவது. a[:], a.copy(), list(a) ……

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