0

I am just experimenting with some things in python, and one of my problems required a funny solution of changing a / to a //. What's the difference?

def is_multiple(number=None, m=None): # m representing times table
    if not number or not m:
        return False
    if isinstance(m//number, float):
        return False
    return True
print(is_multiple(4, 12)) # returns True
def is_multiple(number=None, m=None): # m representing times table
    if not number or not m:
        return False
    if isinstance(m/number, float):
        return False
    return True
print(is_multiple(4, 12)) # returns False

I would expect both to work the same, can someone explain the difference? Thanks :)

xupaii
  • 465
  • 4
  • 15
  • 31
  • 1
    `m//number` is an int. `m/number` is a float. – dildeolupbiten Jul 18 '19 at 20:28
  • 1
    Depending on if you are running Python 2 or Python 3, one of `/` is regular division, and one of `//` is integer (floor) division. From the Python repl try: `11//5` and see what the answer is. – mgrollins Jul 18 '19 at 20:29
  • 1
    You can also find information on the difference [here] (http://www.informit.com/articles/article.aspx?p=674692&seqNum=4) – plum 0 Jul 18 '19 at 20:30

0 Answers0