"Support Desk" <support.desk.i pg@gmail.comwro te in message
news:01da01c8e1 fb$7615a4f0$a70 1a8c0@office.ip global.net...
The variable assignment should survive outside the if statements:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
on win32
Type "copyright" , "credits" or "license()" for more information.
value = "impossible "
value = "possible"
possible
You probably want to watch out for the possibility that both Condition1 and
Condition2 are false; otherwise, you will get a NameError when you try to
access Variable without initializing it.
(By the way, as a matter of style, Python variable names are usually written
in all lower-case letters.)
Russ
news:01da01c8e1 fb$7615a4f0$a70 1a8c0@office.ip global.net...
I am trying to assign a variable using an if / else statement like so:
If condition1:
Variable = something
If condition2:
Variable = something else
Do stuff with variable.
>
But the variable assignment doesn't survive outside the if statement. Is
there
any better way to assign variables using an if statement or exception so I
don't
have to write two almost identical if statements. This is probably a dumb
question.
Variable = something
If condition2:
Variable = something else
Do stuff with variable.
>
But the variable assignment doesn't survive outside the if statement. Is
there
any better way to assign variables using an if statement or exception so I
don't
have to write two almost identical if statements. This is probably a dumb
question.
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
on win32
Type "copyright" , "credits" or "license()" for more information.
>>if "yes" == "no":
>>if "no" == "no":
>>print value
>>>
Condition2 are false; otherwise, you will get a NameError when you try to
access Variable without initializing it.
(By the way, as a matter of style, Python variable names are usually written
in all lower-case letters.)
Russ