Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
x = 5
y = x
print(y)

So basically i want to print X not rhe value


Print(x) will give 5

i am expecting Print(y) should give X

What I have tried:

x = 5
y = x
print(y)
Posted
Updated 7-Jan-20 3:21am

It doesn't work this way. You'd have to do print("x"). no language tracks which variable another variable was set with, unless it's a reference variable and they are both the same object
 
Share this answer
 
Short answer: you don't.
In the code what actually happens is:
Python
x = 5    # variable x now contains the value 5
y = x    # variable y now contains a copy of variable x, that is the value 5
print(y) # prints whatever value is in y
 
Share this answer
 
Quote:
How do I print right hand side value in Python

Short answer: you don't.
The main reason is that y don't know where its value comes from.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900