0

What's the difference between 1 and 1.0? Do they have different use?

Is there any difference between 1 and 1.0? For example what's the difference between' print ('1') and print('1.0')

7th Jul 2021, 3:46 AM
AJ Aj
AJ Aj - avatar
2 Réponses
+ 4
1 is integer type 1.0 is float type By default in python, numeric value are of float type and not integer. So, print(1) #output 1.0 print(1.0) #output 1.0
7th Jul 2021, 4:26 AM
minirkk
minirkk - avatar
0
Rohit Hi! When you print an integer in Python, you got a integer as a result, not a float. Otherwise it should be strange. When you print out a float, of course you got a float. When you add a integer and a float, you got a float. >>> print(1) 1 >>> print(1.0) 1.0 >> print(1 + 1.0) 2.0
14th Dec 2021, 6:07 PM
Per Bratthammar
Per Bratthammar - avatar