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

后端 未结 8 1638
迷失自我
迷失自我 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 20:01

    It uses indentation

     def func():
         funcbody
         if cond: 
             ifbody
         outofif
    
     outof_func 
    
    0 讨论(0)
  • 2020-12-04 20:01

    So its the indentation that matters. As other users here have pointed out to you, when the indentation level is at the same point as the def function declaration your function has ended. Keep in mind that you cannot mix tabs and spaces in Python. Most editors provide support for this.

    0 讨论(0)
提交回复
热议问题