>> operator in Python

后端 未结 5 1629
无人及你
无人及你 2020-11-30 08:48

What does the >> operator do? For example, what does the following operation 10 >> 1 = 5 do?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 09:15

    You can actually overloads right-shift operation(>>) yourself.

    >>> class wierd(str): 
    ... def __rshift__(self,other): 
    ... print self, 'followed by', other 
    ... 
    >>> foo = wierd('foo') 
    >>> bar = wierd('bar') 
    >>> foo>>bar 
    foo followed by bar 
    

    Reference: http://www.gossamer-threads.com/lists/python/python/122384

提交回复
热议问题