Python parameter list with single argument
问题 When testing Python parameter list with a single argument, I found some weird behavior with print . >>> def hi(*x): ... print(x) ... >>> hi() () >>> hi(1,2) (1, 2) >>> hi(1) (1,) Could any one explain to me what the last comma mean in hi(1) 's result (i.e. (1,) ) 回答1: Actually the behavior is only a little bit "weird." :-) Your parameter x is prefixed with a star, which means all the arguments you pass to the function will be "rolled up" into a single tuple, and x will be that tuple. The