+ 2

So then why don't we add a float number? 20 // 6 is 3, but why isn't it defined as 3.33 or something alone those lines?

11th Mar 2017, 8:59 AM
MynameisKyle99
MynameisKyle99 - avatar
2 Answers
+ 6
Python has two division operators: '/' is used for true division and '//' is used for floor division. The true division operator returns a float, and the floor division operator returns an int. So if you want to get 3.333 as result you probably what the true division operator. But if you want the result without the remainder use the floor division.
11th Mar 2017, 3:57 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
// is dividend operator. For instance, 20 divided by 6 gives 3 (2 remainder). So 20//6 = 3. Also you might confuse that with division operator (/), which gives your example 3.33 as the result
11th Mar 2017, 11:26 AM
KhĂŽi Nguyễn Minh
KhĂŽi Nguyễn Minh - avatar