Returning tuple with a single item from a function

前端 未结 4 2033
挽巷
挽巷 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:48

    Instead of that ugly comma, you can use the tuple() built-in method.

    def returns_tuple_of_one(a):
        return tuple(a)
    

提交回复
热议问题