eval evaluates python code or lets Python program run Python code within itself.
example:
CODE:
a = 15
eval('print(a + 3)')
OUTPUT:
18
when you return the following
eval(((str(a)+"*")*b)[:-1])
what you basically doing is this( for example if you are computing power(2,5)):
str(a) -> changes the value of a to string. in this case "2"
str(a)+"*" -> concatinate the above string to the multiplication sign. now we have "2*"
(str(a)+"*")*b) -> duplicates the above string b times. That is "2*"+"2*"+"2*"+"2*"+"2*", that is five times and now you have "2*2*2*2*2*"
But as you can see there is an extra "*" at the end. To remove this one we use [:-1]. what this basically doing is select all except the last one. ":" basically means all.
so the final expression to be evaluated is "2*2*2*2*2"
. which is 2^5.