I'm going from Java to Python and I would like to know if I have the ability to ask a variable to be an integer and never attempt to cast itself in something else.
# A method that return a floating point number
def afloatvalue():
return 20.1
# Here is a variable i I would like to be an integer
i = 15
# But of course, this assignment changes it to a floating point number.
i = afloatvalue()
print(i)
Output : 20.1
(normal)
But I would like i
to be stay absolutely an integer anywhere in the program (like in Java), so that :
i = afloatvalue()
Would lead to 20
.
Is it possible by using some keyword when defining it ?
i : int = 15
doesn't grant this guarantee.