Returning tuple with a single item from a function

前端 未结 4 2042
挽巷
挽巷 2020-12-01 21:14

Just came across this little bit of weirdness in Python and thought I\'d document it write it as a question here in case anyone else is trying to find

4条回答
  •  我在风中等你
    2020-12-01 21:41

    You need to explicitly make it a tuple (see the official tutorial):

    def returns_tuple_of_one(a):
        return (a, )
    

提交回复
热议问题