+ 35

Why is 8/2=4.0 and not 4?

26th Oct 2016, 4:23 PM
Jaya
75 Answers
+ 190
In Python by default take float data type So any division calculations it will give us floating value Suppose that 24/12 = 2.0 not 2 But 24 // 12 = 2 not 2.0 Try to understand difference / - is division it will give floating value // - is floor division it will give integer value
26th Oct 2016, 8:22 PM
Ugra Narasimha
Ugra Narasimha - avatar
+ 19
Division always give floating point number. That's why 8/2 = 4.0
26th Oct 2016, 4:29 PM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 12
Because a / operation returns a float. If you want to do an euclidian division, use //.
26th Oct 2016, 4:29 PM
Zen
Zen - avatar
+ 6
in python default data type is float if you use 2/2 gives float data type as 1.0 or if you use 2//2 gives you 1 which is an integer.
24th Nov 2016, 5:21 AM
shreyanshu shankar pandey
shreyanshu shankar pandey - avatar
+ 5
thanks for this que.
18th Dec 2016, 5:59 AM
Sanjay Soni
Sanjay Soni - avatar
+ 4
When it comes to python, you always get the answer ( if you not change the data type, you able to get the result) in float data type
26th Apr 2017, 2:55 PM
Isura Gayan
Isura Gayan - avatar
+ 2
Will division of floating numbers using // also give whole numbers?
26th Oct 2016, 4:33 PM
Jaya
+ 2
@Pratik .... Yeah exactly result of division is always be be a float number. Like If you divide 6/2 it's answer will be 3.0 not 3
3rd Nov 2016, 3:01 PM
Waqas Asghar Bhalli
Waqas Asghar Bhalli - avatar
+ 2
division(/) sets float data type.
11th Nov 2016, 6:06 PM
Shikhar Chawra
Shikhar Chawra - avatar
+ 2
inpython values are taken by default in float
17th Dec 2016, 9:59 AM
Bruh
+ 2
python always gives access result of division as a floating number. but if you want to get a whole number by a division you have to use floor division . like this 8//4
18th Dec 2016, 6:05 AM
Isura Gayan
Isura Gayan - avatar
+ 2
When ever you divide using a forward slash it results in a float. A float is a decimal.
6th Aug 2020, 10:14 PM
Jrod
Jrod - avatar
+ 1
that's because normally when a number is divided in programming languages like python and java and some other using / sign we get output is float data type..!
27th Oct 2016, 5:17 PM
Damodar Bajaj
+ 1
This is one of the new features of python3 vs. python2 in python2 you can start your programme with "from __future__ import division" to reproduce python3 division
29th Oct 2016, 10:46 AM
Raphael Murray
Raphael Murray - avatar
+ 1
division with / in Python always results in a float value
24th Dec 2016, 7:37 AM
Nelson Young II
Nelson Young II - avatar
+ 1
python silently convert integer into float
26th Dec 2016, 7:12 PM
Ningyao Ningshen
Ningyao Ningshen - avatar
+ 1
en python toujours la division donne un float
3rd Jan 2017, 1:35 PM
Chouaib RACHDI
Chouaib RACHDI - avatar
+ 1
8/2=4.0 and 8//2=4 !!!
23rd Jan 2017, 4:07 PM
FAGO LION
FAGO LION - avatar
+ 1
but,python is a interpreted language so,it is convert all number in floating numbers.
9th Feb 2017, 2:08 PM
Sudani Chintan
Sudani Chintan - avatar
+ 1
Thank you for this post :)
18th Feb 2017, 2:47 PM
Brent