+ 6
I got question in define a function in Python
count=0 def mine(): while count<10 count+=1 print(count) mine() output is Unbound Local Error which means count must be inside function(def) so all variables should inside def Am I correct??? Also I'm troubling in def for long time if anyone can explain about function shortly!
2 Respuestas
+ 6
Yes, you are right. The variable `count` can be accessed by functions, but not modified by them unless you use the `global` keyword like this: ```
count = 0
def mine():
global count
while count < 10:
count += 1
print(count)
mine()
```
+ 6
yes the variable must be inside the function