I'm learning socket programming in Python, and saw that a person used this piece of code:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
Why would you use with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s
instead of s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
? Is there any difference between these which makes one better to use in this case?