Why can't I use a starred expression?

前端 未结 3 405
别那么骄傲
别那么骄傲 2020-12-23 16:41

My code

$ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type \"help\", \         


        
3条回答
  •  萌比男神i
    2020-12-23 17:15

    My question, why?

    Because your python syntax doesn't allow that. It's defined that way, so there's no real "why".

    also, it's unnecessary.

    "%d %d" % a
    

    would work.

    So, you'd need to convert your expansion to a tuple – and the right way of doing that would be, as pointed out by Lafexlos, be

    "%d %d" % (*a,)
    

提交回复
热议问题