+ 1
Why it shows error
6 Antworten
+ 5
See it's showing an error because u haven't defined 👉🏻(a).
So let us take👉🏻 (a=24)
Now u code will become as:
a=24
def func(a):
print(a)
a+=1
print(a)
print(a)
func(7)
+ 4
'a' is a local variable means access to 'a' is limited to the scope where it was declared.
Here scope of 'a' is the function . you can only access 'a' within the function.
Trying to access it in outside of function giving you error on line 6
+ 1
I tried inside still it shows error
+ 1
Akash Prasad you have to create another variable outside function named 'a' .
https://code.sololearn.com/cLAukOluKbyJ/?ref=app
0
Global variable 'a' is not defined.
0
def func(a):
print(a)
a+=1
print(a)
func(7)
a is not a global variable