what is y Displayed in the following code
x = 1
y = x = x + 1
print("y is",y)
Answers
Answered by
2
Answer:
output of this code will be
y is 2
Answered by
0
Answer:
Nothing will be output unless you give a print command.
If in python print(x) gives 6
Print (y) gives 4
Print(x,y) gives 6 4
It's easy to understand this way in programming.
Variables are like boxes,and the values on right hand sides are like things in boxes.
First you told computer that x= 2 and y= 6
Then you told x= y
Remember that all right hand side of = deals with values so x= 6
Then y = x+2 = 2+2 = 4
Here you may ask why I didn't take x as 6
In the command you gave x,y= y,x+2
You used , to merge two assignments
So they do that simultaneously meaning at the same time
Comment if I'm wrong:)
Similar questions
English,
3 months ago
Science,
3 months ago
Computer Science,
7 months ago
Math,
7 months ago
Chemistry,
11 months ago