Python star unpacking for version 2.7

前端 未结 3 389
礼貌的吻别
礼貌的吻别 2020-12-06 03:59

As mentioned here, you can use the star for unpacking an unknown number of variables (like in functions), but only in python 3:

>>> a, *b = (1, 2, 3         


        
3条回答
  •  忘掉有多难
    2020-12-06 04:24

    answer to ex13.py

    from sys import argv
    
    script=argv
    
    def Fun(arg1, *argv): 
        print "First argument :", script 
    
        for arg in argv: 
            print"Your variable is:", arg
    
    Fun('scrpit', 'first', 'second', 'third')
    

提交回复
热议问题