Python Forum
TypeError: unsupported operand type(s) for ** or pow()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for ** or pow()
#4
This isn't your issue, but for general knowledge here the python builtin pow actually takes a third argument to mod by to take advantage of modular exponentiation.

So like pow(456, 89700, 17) instead of (456**89700) % 17.

Interestingly enough though the interpreter does seem smart enough to use modular exponentiation in the second case as well but I'm not sure if this is part of spec or just an implementation detail you can't rely on.  If you tried to do the exponentiation in one expression and then the mod in another though your program could take eons.

Edit: Actually on second thought I think the second version is done inefficiently. The first version should always be much faster.
Reply


Messages In This Thread
RE: TypeError: unsupported operand type(s) for ** or pow() - by Mekire - Sep-06-2017, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Type Error: Unsupported Operand jhancock 2 1,272 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 9,388 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 2,253 May-07-2022, 08:40 AM
Last Post: ibreeden
  unsupported operand type(s) for %: 'list' and 'int' RandomCoder 4 32,942 May-07-2022, 08:07 AM
Last Post: menator01
  You have any idea, how fix TypeError: unhashable type: 'list' lsepolis123 2 3,063 Jun-02-2021, 07:55 AM
Last Post: supuflounder
  TypeError: __str__ returned non-string (type tuple) Anldra12 1 7,444 Apr-13-2021, 07:50 AM
Last Post: Anldra12
  unsupported operand type(s) for /: 'str' and 'int' Error for boxplot soft 1 3,095 Feb-09-2021, 05:40 PM
Last Post: soft
  TypeError: 'type' object is not subscriptable Stef 1 4,573 Aug-28-2020, 03:01 PM
Last Post: Gribouillis
  TypeError: unhashable type: 'set' Stager 1 2,645 Jun-08-2020, 04:11 PM
Last Post: bowlofred
  TypeError: __repr__ returned non-string (type dict) shockwave 0 3,213 May-17-2020, 05:56 PM
Last Post: shockwave

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020