Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make global empty integer?

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
like image 974
F.Fipoo Avatar asked May 06 '26 15:05

F.Fipoo


1 Answers

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()
like image 102
Fady Saad Avatar answered May 09 '26 04:05

Fady Saad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!