Quote:
Ques 1.
x=+1
This will always be 1 as it's an assignment not an increment.
If you do x
+=1 without initializing, it will throw an error.
Quote:
Ques 2.
output:4,12
This happened as during the compiler run, value of b was already defined as 12 in sequence of code. (It is not a reference that will be updated if x changes later). For more clarity, have updated your code to show how execution happened and values of variables were being used:
x=12
print('W',x)
def f1(a,b=x):
print('X',x)
print(a,b)
x=15
print('Y',x)
f1(4)
print('Z',x)
Output for it is:
W 12
Y 15
X 15
4 12
Z 15
You can see the value of x did change to 15 before the function call (even x value is 15 inside), but the value of b was set to 12 as it was the case when the function definition was setup in execution.