python 中的嵌套循环列表理解;无法识别外循环中的变量

nested loop list comprehension in python ; can't recognize variable in outer loop

def  maxXor( l,  r):
return max(a^b for b in range(a,r+1) for a in range(l,r+1))

报错显示NameError: global name 'a' is not defined.

我认为错误是range(a,r+1)

这里我想要'a' in range(a,r+1) reference 'a' in inner loop for a in range(l,r+1)).

def  maxXor( l,  r):
    return max(a^b  for a in range(l,r+1) for b in range(a,r+1))