I would like to know why this is valid:
set(range(10)) - set(range(5))
but this is not valid:
set(range(10)) + set(range(5))
Is it because ‘+’ could mean both intersection and union?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Python sets don’t have an implementation for the
+operator.You can use
|for set union and&for set intersection.Sets do implement
-as set difference. You can also use^for symmetric set difference (i.e., it will return a new set with only the objects that appear in one set but do not appear in both sets).