Python Flashcards

1
Q

Class method vs Static method

A
static is just utility. It exists in class because logically it makes sense to be in that class.
class method uses cls variable (It's not instance but a class method). Class method can be used in factory methods etc. (Read more about usage of class method)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

return (2 - N) % 7 - what does this return and why

A

modulo always return the same sign as denominator. it’ll return 7 - (abs(x%7)) in case x is negative

How well did you know this?
1
Not at all
2
3
4
5
Perfectly