“add to set” returns a boolean in java - what about python?

前端 未结 5 778
小蘑菇
小蘑菇 2021-01-11 17:24

In Java I like to use the Boolean value returned by an \"add to the set\" operation to test whether the element was already present in the set:

if (set.add(\         


        
5条回答
  •  [愿得一人]
    2021-01-11 18:17

    As mentioned in the previous answers, the add method for Python sets does not return anything. By the way, this exact question was discussed on the Python mailing list: http://mail.python.org/pipermail/python-ideas/2009-February/002877.html.

提交回复
热议问题