Assignment and comparison in one statement

Johannes Bauer dfnsonfsduifb at gmx.de
Fri May 23 18:59:58 EDT 2008


Hello group,

I'm just starting with Python and am extremely unexperienced with it so 
far. Having a strong C/C++ background, I wish to do something like

if (q = getchar()) {
	printf("%d\n", q);
}

or translated to Python:

if (p = myfunction()):
	print p

However, this "assignment and comparison" is not working. What's the 
"Python way" of doing this kind of thing?

Thanks a lot,
Johannes

-- 
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen."     -     Wolfgang Gerber
       in de.sci.electronics <47fa8447$0$11545$9b622d9e at news.freenet.de>



More information about the Python-list mailing list