0
WAP
Write a program that does following: 1. Define a variable with value 10 viz. a 2. Define another variable with value 20 viz. b 3. Copy the variable a into variable b 4. Change value of a to 30 5. Print value of both a and b. Explain what happened and why?''' a= (10) b= (20) b= (a) a= (30) print("The value of a=", a) print("The value of b=", b) It is Right or wrong ?
1 Odpowiedź
0
Your code is fine but no need for the parentheses.
1.First you have defined a variable with value 10.
2.Then you have defined a variable with value 20.
3.Then you have updated the variable b value with the variable a value and variable b value will be 10
4. Then you have printed the variable where you updated it's value to 30.
And then you have printed b with it's value of 10.
In python. If a same variable name gets a updated it will go for the new value instead of the old one.
Eg.
a = 10
b = 10
a = 30
b = 40
print(a)#outputs 30
print(b)#outputs 40