What does -> mean in Python function definitions?

后端 未结 8 1528
我寻月下人不归
我寻月下人不归 2020-11-22 07:29

I\'ve recently noticed something interesting when looking at Python 3.3 grammar specification:

funcdef: \'def\' NAME parameters [\'->\' test] \':\' suite
         


        
8条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 07:50

    def function(arg)->123:

    It's simply a return type, integer in this case doesn't matter which number you write.

    like Java :

    public int function(int args){...}
    

    But for Python (how Jim Fasarakis Hilliard said) the return type it's just an hint, so it's suggest the return but allow anyway to return other type like a string..

提交回复
热议问题