I was trying to use Python and I have created a short method:
def mul(x,y):
print(x*y)
by running mul(2,"23")
, I'm getting this outstanding output : 2323
Can someone explain this?
Because you're multiplying a string and an integer together:
>>> print '23' * 2
2323
Which is equivalent to '23' + '23'
.
Do mul(2, int('23'))
to turn '23'
into an integer, or just get rid of the quotation marks surrounding the 23
.
By the way, such function already exists in the operator
module:
operator.mul(2, 23)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With