What is the purpose of the __neg__ and __pos__ methods? #22
Answered
by
lukasmiller3
lukasmiller1
asked this question in
Q&A
-
|
What is the purpose of the neg and pos methods? |
Beta Was this translation helpful? Give feedback.
Answered by
lukasmiller3
Jan 22, 2026
Replies: 1 comment
-
|
A:neg implements unary negation (-obj), pos implements unary plus (+obj). They're used by the - and + operators on objects. neg should return a negated value, pos typically returns the object unchanged or a copy. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lukasmiller1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A:neg implements unary negation (-obj), pos implements unary plus (+obj). They're used by the - and + operators on objects. neg should return a negated value, pos typically returns the object unchanged or a copy.