0

I am watching a video on youtube about OOP. I encountered a type of syntax that I could not understand by my past information. The author calls the static method inside the method writing the argument at the beginning of the method's name. The method's function is to detect whether the passed number is an integer or not. The code is below:

class Dog:
    
    @staticmethod
    def is_integer(num):
        if isinstance(num,float):
            return num.is_integer()
        elif isinstance(num,int):
            return True
        else:
            return False

My problem is this:

What is the syntax behind num.is_integer()?

0

1 Answer 1

1

The method definition is using a method of float objects that has the same name, it's not calling itself. The isinstance(num, float) is making sure that it is actually used on a float, otherwise the program would throw an exception. If it would call itself, it would look more like Dog.is_integer(num).

Sign up to request clarification or add additional context in comments.

1 Comment

Therefore, I was confused with using the built-in method "is_integer" and our own static method's name :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.