Hello ,
In Python, we can divide Numerics types in 2 parts in general. As Integer and Float.
number1 = 100 number2 = 203123123123123125430 number3 = -300 print(number1) # 100 print(number2) # 203123123123123125430 print(number3) # 300
How can we find out that the type of a variable is really int?
print(type(number1)) # <class 'int'> print(isinstance(number1, int)) # True
Well I have a string value. how do i cast this to int?
street_no = "15" print(type(street_no)) # <class 'str'> street_no_int = int(street_no) print(type(street_no_int)) # <class 'int'>
Converting the float type to int would be the same.
my_float_no = 10.1 my_int_no = int(my_float_no) print(type(my_int_no)) # <class 'int'>
Now let’s look at the impressions of float type
number4 = 10.112 number5 = -10.54 print(type(number4)) # <class 'float'>
Int is very simple if we want to convert a int into a float number
print(number3) # -300 number6 = float(number3) print(number6) # -300.0