0
If-else statement vs ternary operator (Performance)
Is there a significant difference in terms of performance (running time, running space, etc) between if-else statements and ternary operators? # if-else statement if average >= 75: print(âPassâ) else: print(âFailâ) # ternary operator / inline statement print(âPassâ if average >= 75 else âFailâ)
2 RĂ©ponses
+ 2
I made a speed test with 2 equivalent statements, but they seem to be very close, but if else statement seems to be a little faster:
https://code.sololearn.com/c0Q4j7fv6Rwb/?ref=app
+ 1
I dont think there is any difference. The second is basically short of the first