assignment in if

Ben Caradoc-Davies ben at wintersun.org
Tue May 2 19:40:27 EDT 2006


Gary Wessle wrote:
> is there a way to make an assignment in the condition of "if"

No.

> nx = re.compile('regex')
> if x = nx.search(text):
>    funCall(text, x))

Use:

nx = re.compile('regex')
x = nx.search(text)
if x:
     funCall(text, x)

-- 
Ben Caradoc-Davies <ben at wintersun.org>
http://wintersun.org/
"Those who deny freedom to others deserve it not for themselves."
- Abraham Lincoln



More information about the Python-list mailing list