4

I am new in python programming. I have come to piece of program in which

if (pos.x//1,pos.y//1) not in self.cleaned:
     self.cleaned.append((pos.x//1,pos.y//1)) 

is used. It might be silly of me. But can anyone please tell me what the code means. And please tell me the function of "//".

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • 2
    Take a look at this: http://stackoverflow.com/questions/183853/in-python-what-is-the-difference-between-and-when-used-for-division – adchilds Apr 15 '13 at 06:38

3 Answers3

8

It is the explicit floor division operator.

5 // 2 # 2

In Python 2.x and below the / would do integer division if both of the operands were integers and would do floating point division if at least one argument was a float.

In Python 3.x this was changed, and the / operator does floating-point division and the // operator does floor division.

References:

http://www.python.org/dev/peps/pep-0238/

alexhb
  • 435
  • 2
  • 12
7

a // b is floor division. It's basically floor(a / b), but it preserves the number type.

Blender
  • 289,723
  • 53
  • 439
  • 496
3

The / operator does a floating-point division, the // operator does integer division.

For example:

>>> 10/4   #will be 2.5
>>> 10//4  #will be 2

Note that this is from python 3.

In python 2. if you try it, you'll get:

>>> 10/4     #will be 2
>>> 10.0/4   #will be 2.5
Maroun
  • 94,125
  • 30
  • 188
  • 241