0

I am trying to determine whether a variable is an integer or not.

I have a variable called arg2 and I need to determine whether arg2 is an integer. If arg2 is not an integer then it will set the value to 0.

How would I determine whether arg2 is an integer or not?

3
  • 4
    isinstance(arg2, int)? Commented Dec 24, 2021 at 16:11
  • 1
    Do you want to check if arg2 has type int, or is a number whose value is or is close enough to an integer? Commented Dec 24, 2021 at 16:13
  • i want to know if it has type int Commented Dec 24, 2021 at 16:13

1 Answer 1

-2

You can test arg2 type this way:

if (type(arg2) != int):
    arg2=0
Sign up to request clarification or add additional context in comments.

Comments