choice()函数参数:关键字arg后的非关键字arg

时间:2016-04-24 18:28:23

标签: python random-sample

tup_list = [1,2,3,4,5]
weight_list = [0.5,0.6,0.1,0.7]   
draw = choice(tup_list, sample_size_d, replace=False, weight_list)

当我尝试运行它时,我收到错误:SyntaxError:关键字arg之后的非关键字arg 我怎么能解决它?

1 个答案:

答案 0 :(得分:0)

此处weight_list是非关键字arg。在Python中调用函数时,所有关键字参数(key = value type)都应遵循所有非关键字参数。您拨打choice的电话应该是:

draw = choice(tup_list, sample_size_d, weight_list, replace=False)

看到这个问题: Python normal arguments vs. keyword arguments