+ 1

Def_function

When defining a function in Python, how do we know that the function has ended or how do we end the function?

25th Aug 2018, 4:43 PM
arbaaz
2 Answers
+ 2
Python use indentation for define code blocks then your function is "ended" when you set a line indentation to be same like before define the function
25th Aug 2018, 4:50 PM
KrOW
KrOW - avatar
+ 2
Just to clarify KrOW's answer, Different indentation levels indicate different scopes in python. What this means is that whatever code is in the next indentation level as compared to the 'def' line is included in the def statement. ---------------- For example: def add(a, b): result = a + b # Indented, therefore in the definition return result # Indented, therefore in the definition print(add(17 + 25)) # Not indented, therefore definition has ended
25th Aug 2018, 7:51 PM
Just A Rather Ridiculously Long Username