I recently came across syntax I never seen before when I learned python nor in most tutorials, the .. notation, it looks something like this:
f = 1..__truediv__ # or 1..__div__ for python 2
print(f(8)) # prints 0.125
I figured it was exactly the same as (except it's longer, of course):
f = lambda x: (1).__truediv__(x)
print(f(8)) # prints 0.125 or 1//8
But my questions are: How can it do that? What does it actually mean with the two dots? And how can you use it in a more complex statement (if possible)?
This will probably save me many lines of code in the future...:)
(1).__truediv__is not really the same as1..__truediv__, as the former callsint.__truediv__while the latter doesfloat.__truediv__. Alternatively, you can also use1 .__truediv__(with a space)` – tobias_k 37 mins ago