Connecting Tech Pros Worldwide Forums | Help | Site Map

using multiple 'if' statements in Python

Newbie
 
Join Date: Jul 2008
Posts: 3
#1: Jul 13 '08
Hi All,

Can anyone please help me out about how can I use multiple 'if' statements in Python like C/C++?

For example in C:
*****************************
int a;
a = 0;

if ( a == 0 ) {
printf "0";
a = 1;
}
if ( a == 1 ) printf "1";
******************************
How can I write these statements in Python Code?

Thanks.

Newbie
 
Join Date: Jul 2008
Posts: 3
#2: Jul 13 '08

re: using multiple 'if' statements in Python


OOPS! Sorry for that. Actually I got some errors in my regular expressions and assumed it as for that multiple 'if' statements!!!! Now I figured it out and solved it.

Sorry for the inconvenience :-)
jlm699's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: Durham, NC
Posts: 313
#3: Jul 14 '08

re: using multiple 'if' statements in Python


In case you're still wondering the if, else structure in Python is:
Expand|Select|Wrap|Line Numbers
  1. if condition 1:
  2.     action 1
  3. elif condition 2:
  4.     action 2
  5. elif condition 3:
  6.     action 3
  7. else:
  8.     default action
  9.  
Reply