Explanation:
x = 10
Here, a variable named x is created and assigned the value 10.
At this moment, x points to the integer 10 in memory.
s = f"{x}"
This line creates an f-string.
The f before the string means formatted string
{x} is evaluated immediately
Since x is 10 right now, {x} becomes "10"
So:
s = "10"
Important: s stores a string, not a reference to x.
x = 20
Now the variable x is reassigned to a new value: 20.
This does not affect s, because s already contains the string "10".
print(s)
This prints the value stored in s.
Output:
10

0 Comments:
Post a Comment