'How to check the result of a function

I have three functions I want to check if the port is open and if it is open, perform function number two, otherwise perform function number three. I wrote the following code but it doesn't work

def port():
    a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    location = (ip, 80)
    check = a_socket.connect_ex(location)
    a_socket.close()


if port() == 0:
    other_function2()
else:
    other_function3()


Solution 1:[1]

You need to return something from the port() function. It is not returning anything right now. Use a return statement to return a value and then you can use the if statement with that value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mobi Zaman