Python def function: How do you specify the end of the function?

后端 未结 8 1656
迷失自我
迷失自我 2020-12-04 19:21

I\'m just learning python and confused when a \"def\" of a function ends?

I see code samples like:

def myfunc(a=4,b=6):
    sum = a + b
    return su         


        
8条回答
  •  情歌与酒
    2020-12-04 19:55

    Interestingly, if you're just typing at the python interactive interpreter, you have to follow a function with a blank line. This does not work:

    def foo(x):
      return x+1
    print "last"
    

    although it is perfectly legal python syntax in a file. There are other syntactic differences when typing to the interpreter too, so beware.

提交回复
热议问题