Using __ipow__ in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

Using __ipow__ in Python

I've been experimenting with Python Magic Methods and I came across __ipow__ So __pow__ can specify a 3rd argument which lets you do a**b%c efficiently by using an inbuilt pow(a,b,c) function. Without the c, you can just do a**b or pow(a,b). Similarly, for __ipow__, you use a**=b but what is the 3 argument equivalent? I've tried searching online to get no clear answer. Can someone help me in finding how to use the __ipow__ magic method with 3 arguments? Thanks!

4th Jun 2019, 8:47 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
4 Answers
+ 9
The __i...__ methods are only implemented for mutable data types like lists because they are not returning a new object but are changing the original one. Thus having a modulo doesn't make any sense. I can't imagine how to modulo a list for example. So yes, that parameter seems to be pretty useless.
5th Jun 2019, 8:41 AM
Thoq!
Thoq! - avatar
+ 6
Kuba Siekierzyński Sorry for pinging you but I feel that you might have an insight into this question, so if possible could you help me?
4th Jun 2019, 8:49 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Николай Шаповаленко so it means that it is useless?
4th Jun 2019, 7:42 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar