A Beginner's Doubts in Python 3.0

I have the following 2 doubts related to Operators in Python:

1. Floor Division:

print(5//2) o/p -> 2
print(-5//2) o/p -> -3 I do not understand the logic behind this division, why is the o/p = -3, and not as -2?

2. Membership Operator:

y = {3:‘a’,4:‘b’}

print(3 in y) -> True
print(‘b’ in y) -> False Why is this FALSE?

Hi @rvgl,

Here, the lower value integer is printed. So in the first case with 2.5, since 2<2.5, we get 2 as the output. In the second case, for the negative values -3<-2.5 and not -2. So the output is -3.

I believe only the keys are recognized and not the values. Since 3 is the key, the result is True and b is not a key so the result is False.

© Copyright 2013-2019 Analytics Vidhya