How to declare global empty integer? I have simple code but i don't know how to declare a variable before def. In java I can do just that: public int a; but how to do it in python? Without this, the third if not working
My code:
def abcd:
if s<0.72:
if e>30:
a=0
return a
else:
a=0
return a
else:
if a == 1:
a = 1
return a
else:
a=1
return a
while True:
abcd
Python is dynamic, so you don't need to declare things; they exist automatically in the first scope where they're assigned. So, all you need is a regular old assignment statement as above.
You can declare as follow, if you want a non-value variable:
a = None
Or you can declare as follow, if you want a zero value int variable:
a = int()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With