python中()和[]用法解释

for w in weights if isinstance(weights, list) else [weights]:
attempt_download(w)
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval())


```请详细讲解一下代码,谢谢
方括号是构成数组,圆括号是函数调用
相当于
if isinstance(weights, list): #如果weights是列表
  for w in weights:
    attempt_download(w)
else:
  for w in [weights]:
    attempt_download(w)

或者可以写
if isinstance(weights, list):
  for w in weights:
    attempt_download(w)
else:
  attempt_download(weights)

学习任何一门语言都是先从最基本的语法开始,这点必须得搞清楚
https://www.runoob.com/python3/python3-list.html
https://www.runoob.com/python3/python3-function.html