I was going through socket programming in Python and I saw this:
sock.getsockname()[1]
Can anyone please explain what is that [1]
is for?
I was going through socket programming in Python and I saw this:
sock.getsockname()[1]
Can anyone please explain what is that [1]
is for?
>>> sock.getsockname()
('0.0.0.0', 0)
The first element of the returned tuple (it is a wird kind of array) sock.getsockname()[0]
is the IP, the second one sock.getsockname()[1]
the port.
tuple[index]
gets the object at this index in the tuple