In python, you can use // to divide integers, and get an integer result. You can also use % to determine if two numbers divide perfectly (% returns the remainder, which is always zero if and only if the two numbers divide perfectly). To accomplish what you're asking, simply:
a = 6
b = 2
if a % b == 0:
result = a // b
else:
result = a / b
That said, you could also simply run the standard division and convert the result to an integer as well...
result = a / b
if result % 1 == 0:
result = int(result)
However, in both of these cases, you might want to examine the broader context of what you're coding, because it can create real problems down the line if a variable is sometimes one data type, and other times a different data type - it might be best to leave the value as a float in every case until such time that you need for it to become an integer.
Note: Using '//' on two integers which do not divide perfectly will still result in an integer, as python will simply ignore the remainder. 6 // 4 = 1, 15 // 2 = 7.