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 Antworten
+ 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