0

Can i use more staments in one line expresion if?

it seems like not :(

21st Feb 2017, 4:37 PM
Ian Maguiña
Ian Maguiña - avatar
8 Answers
+ 3
You want to say "conditions" maybe? What call you "statement"? You cannot do : if x > 0: if x < 10: But you can do: if x > 0 and x <10: As well as: if 0 < x < 10: And combining as many 'and' and 'or' chained conditions...
21st Feb 2017, 4:50 PM
visph
visph - avatar
+ 1
If you mean putting more than one statement on a line then yes, but the statements will need to end with a semicolon. print ("1st"); print ("2nd");
21st Feb 2017, 4:53 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
@Robin, not it doesn't. x++ is a syntax error in Python. Also, I tried your code, and it says "SyntaxError: invalid syntax" for the "x = 0" You just can't Python...
21st Feb 2017, 9:57 PM
Amaras A
Amaras A - avatar
0
@Robin I think you're confused. That would be a for loop not an if statement.
21st Feb 2017, 5:19 PM
ChaoticDawg
ChaoticDawg - avatar
0
sorry my english isn't good , i was talking about logic conditions , i used &&, || , but recently i saw that would be (and , or )
22nd Feb 2017, 4:52 PM
Ian Maguiña
Ian Maguiña - avatar
- 1
many times when writting an if statement, you have 3 peramiters if (start condition, logic, end conditon) it would look something like this if (x=0, x < 3, x++) (code to be executed) else............. so if you have an if statement that takes on many parameters, it may be more usefull to use a switch statement.
21st Feb 2017, 5:16 PM
Robin
Robin - avatar
- 1
i mistook the code for javascript. sorry about that. and no i cant pyton at all lol. at least not yet 😐 in javascript x++ would just add 1 to x
22nd Feb 2017, 4:53 PM
Robin
Robin - avatar
- 2
@chaoticdawg it works for both
21st Feb 2017, 5:48 PM
Robin
Robin - avatar