What is the point of the comma operator when a tuple only has one entry in python?
This section of code is taken from one of the Pytorch tutorials, I have just removed the non-essential parts so it doesn't error out and added some print statements. The question I have is why the two print statements I provided have slightly different results? Is this a tuple with nothing in the second half of it? I am confused by the comma without anything after it before the assignment operator.

import torch

class MyReLU(torch.autograd.Function):
    @staticmethod
    def forward(ctx, input):
        ctx.save_for_backward(input)
        return input.clamp(min=0)

    @staticmethod
    def backward(ctx, grad_output):
        input, = ctx.saved_tensors
        print("ctx ", ctx.saved_tensors)
        print("inputs ", input)
        grad_input = grad_output.clone()
        grad_input[input &lt; 0] = 0
        return grad_input

relu = MyReLU.apply
relu = MyReLU.apply
y_pred = relu(x.mm(w1)).mm(w2)
loss = (y_pred - y).pow(2).sum()
loss.backward()


Output

ctx  (tensor([[-34.2381,  18.6334,   8.8368,  ...,  13.7337, -31.5657, -11.8838],
        [-25.5597,  -6.2847,   9.9412,  ..., -75.0621,   5.0451, -32.9348],
        [-56.6591, -40.0830,   2.4311,  ...,  -2.8988, -18.9742, -74.0132],
        ...,
        [ -6.4023, -30.3526, -73.9649,  ...,   1.8587, -23.9617, -11.6951],
        [ -3.6425,  34.5828,  27.7200,  ..., -34.3878, -19.7250,  11.1960],
        [ 16.0137, -24.0628,  14.4008,  ...,  -5.4443,   9.9499, -18.1259]],
       grad_fn=&lt;MmBackward&gt;),)
inputs  tensor([[-34.2381,  18.6334,   8.8368,  ...,  13.7337, -31.5657, -11.8838],
        [-25.5597,  -6.2847,   9.9412,  ..., -75.0621,   5.0451, -32.9348],
        [-56.6591, -40.0830,   2.4311,  ...,  -2.8988, -18.9742, -74.0132],
        ...,
        [ -6.4023, -30.3526, -73.9649,  ...,   1.8587, -23.9617, -11.6951],
        [ -3.6425,  34.5828,  27.7200,  ..., -34.3878, -19.7250,  11.1960],
        [ 16.0137, -24.0628,  14.4008,  ...,  -5.4443,   9.9499, -18.1259]],
       grad_fn=&lt;MmBackward&gt;)


It's just an edge-case of unpacking a single-element list or tuple.

a, = [1]
print(type(a), a)
# &lt;class 'int'&gt; 1


Without the comma, a would have been assigned the entire list:

a = [1]
print(type(a), a)
# &lt;class 'list'&gt; [1]


And the same goes for a tuple:

a, = (1,)  # have to use , with literal single-tuples, because (1) is just 1
print(type(a), a)
# &lt;class 'int'&gt; 1

a = (1,)  # have to use , with literal single-tuples, because (1) is just 1
print(type(a), a)
# &lt;class 'tuple'&gt; (1,)

