Hi,
I have a very simple question:
first of all, my code:
import os
def test():
x = "Linux"
y = "Windows"
if os.name == "posix":
print(x)
if os.name == "nt":
print(y)
else:
print("there is a problem")
Run that code on Linux (don't know about windows) and it'll print both Linux and there is a problem.
Now do this:
import os
def test():
x = "Linux"
y = "Windows"
if os.name == "posix":
print(x)
elif os.name == "nt":
print(y)
else:
print("there is a problem")
This time it'll work perfectly. The question is: why does it work with elif but not with two if's?
I was told that it was the same, only that elif is more elegant, but know I see there must be a difference. Any thoughts?
Thank you