What does -> mean in Python function definitions?

后端 未结 8 1626
我寻月下人不归
我寻月下人不归 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:52

    def f(x) -> str:
    return x+4
    
    print(f(45))
    
    # will give the result : 
    49
    
    # or with other words '-> str' has NO effect to return type:
    
    print(f(45).__class__)
    
    
    

提交回复
热议问题