What is the difference between "1" and "1.0" in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between "1" and "1.0" in python

Example: Print((4+8)/2) In this statement the answer"6.0" is right and "6" is wrong. What is the main reason ?

6th Dec 2020, 12:22 PM
Khan Hamza Khan
Khan Hamza Khan - avatar
7 Answers
+ 6
Division results in a float result, e.g. 6.0. 6 is an integer
6th Dec 2020, 12:25 PM
Lisa
Lisa - avatar
+ 5
When arithmetic expression uses floor division ("/") it returns a floating point value. If you want to return an integer value you have to use integer division("//") instead of floor division("/").
6th Dec 2020, 12:43 PM
Yasara hasini
+ 2
One is float (means with decimal point like 8.8888) and other one is integer (means whole number like example 8) :) and / means division but it will give output of float to get the integer you have to use //
7th Dec 2020, 4:28 PM
Sayyam Jain
Sayyam Jain - avatar
+ 2
Khan Hamza Khan No problem but use search bar for these FAQ because these questions are asked already too many times it will be much easy to get these answers from there and fastly
7th Dec 2020, 5:20 PM
Sayyam Jain
Sayyam Jain - avatar
0
Thank you all 😍
7th Dec 2020, 4:57 PM
Khan Hamza Khan
Khan Hamza Khan - avatar
7th Dec 2020, 5:23 PM
Khan Hamza Khan
Khan Hamza Khan - avatar
0
Put simply, 1 is an integer, 1.0 is a float. (though this has been said by many other people).
7th Dec 2020, 11:30 PM
Aria
Aria - avatar