1. CLONING AND PARAMETERS IN ……
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.
இந்த இரண்டு concepts Python-ல் குறிப்பாக lists, mut……
Cloning என்பது ஒரு existing object-ன் contents-ஐ வைத்து ஒரு புதிய independent object உருவாக்கு……
Aliasing-ல்: b = a இதனால்: a ----\ ---> [10, 20, 30] b ----/ ஒரே list object. ஆனால் cloning: b = a[:] இ……
Original: a = [10, 20, 30] Memory concept: a ---> [10, ……
List cloning செய்ய பல ways உள்ளன. Method 1 - Slicing b……
b[0] = 100…
a = [10, 20, 30] Original list. b = a[:] a-வின் elements c……
Again a unaffected.…
Memory: a ----\ ---> [10,20] b ----/ If: b.append(30) then: a = [10,20,30] b = [1……
== AND is WITH CLONING a = [1……
Why? a == b checks values. Values same. So: True But: a is b checks object identi……
இதில் problem இல்லை. ஆனால் nested li……
b clone என்றால் a ஏன் change ஆனது? Because copy() outer list-ஐ மட்டும் புதியதாக உருவாக்கியது. Inner lists sha……
a = [[1, 2], [3, 4]]…
b[0][0] = 100…
Cloning பற்றி முக்கியமான points: Cloning creates a separate object. b = a cloning அல்ல; அது aliasing. a[:] cl……
Wrong assumption: a = [1, 2] b = a இதனை clone என்……
Alias: Same list, two names Clone: Same values, two lists Sho……
Parameter என்பது function definition-ல் data receive செய்ய பயன்படுத்தப்படும் variable. ……
இங்கே: name ஒரு parameter.…
ஒரு function ஒரு machine என்ற……
அந்த value-ஐ receive செய்யும்……
Call: square(5) இங்கு: 5 = argument PAR……
இங்கே: a, b = parameters Func……
Function call: function_name(……
add(10, 20)…
def add(a, b): Function name: add Parameters: a, b Function……
1. MULTIPLE PARAMETERS…
Parameters: name mark Argumen……
1. POSITIONAL PARAMETERS / AR……
Python normally arguments-ஐ pos……
name = "Ravi" age = 20 POSITION MA……
But: subtract(5, 10)…
Position changed, result chan……
1. KEYWORD ARGUMENTS…
Parameter names பயன்படுத்தி a……
இங்கே order change ஆனாலும் par……
1. DEFAULT PARAMETERS…
Parameter-க்கு default value ……
Call with value: greet("Ravi")…
If: greet() then: name = "Student" If: greet("Ar……
1. LIST AS PARAMETER…
இது mutability மற்றும் aliasi……
add_item(a)…
Function call: add_item(a) Functio……
a ----\ ---> [10, 20, 30] x ----/ Inside function: x.append(40) same list modify செய்யப்படுகிறது. So:……
Because list is mutable. PARA……
change(numbers)…
Why? Inside function: data = [100, 200] existing list-ஐ modify செய்யவில்லை. Parameter variable data மட்டும் n……
Because integer is immutable.……
new integer object-க்கு x rea……
change(text)…
String immutable. Function lo……
Mutable Parameter def f(x): x.append(10) List passed: Original may change Immutable Parameter de……
1. Positional parameters 2. Default parameters 3. Ke……
Unknown number of positional arguments r……
*args values tuple-ஆக collect……
total(10, 20, 30)…
1. **kwargs…
**kwargs usually dictionary ஆ……
Parameters பற்றி முக்கியமாக நினைவில் கொள்ள: Parameter function definition-ல் இருக்கும். Argument function cal……
def add(a, b): print(a + b) a……
TypeError Reason: Two required par……
def add(a, b): print(a + b) a……
Default parameter order: Wrong: def show(a=10, b): print(a, b) SyntaxError……
Assuming function always copies a list: def change(x): x.append……
Parameter vs Argument: P = Place holder A = Actua……
What is cloning?…
Which creates an alias? b = a……
Which creates a shallow list ……
In: def add(x, y): x and y ar……
In: add(10, 20) 10 and 20 are:…
What is cloning in Python lists? Cloning is the cre……
Both refer to same object. Cl……
Separate outer list objects. What is a parameter? A parameter is a variable in a fu……
Argument: f(10)…
Which statement creates a clo……
A shallow copy of a nested li……
Which module is used for deep……
Which one is a parameter? def……
Which one is an argument?…
1. Predict the output…
a = [1, 2, 3] b = a[:] b[0] =……
1. Predict the output…
a = [1, 2] b = a b.append(3) ……
1. Identify parameter and arg……
def cube(n): print(n ** 3) cu……
1. Predict the output…
def add_item(x): x.append(100……
1. Predict the output…
def change(x): x = x + 5 n = ……
Cloning Cloning = separate copy Exa……
b = a -> same object b = a.copy() -> separate outer object Nested list: copy() -> shallow copy deepcopy() -> ……
Cloning என்பது existing list-ன் contents-ஐ வைத்து separate list object உருவாக்குவது. a[:], a.copy(), list(a) ……