+ 1
Can somebody explain def functions and related things And a example
3 Antworten
+ 1
Thank you and gor coding large scale things is this required.
0
Python comes with several pre-defined functions. Usually during the development process, you will be creating your own for whatever use you require them for.
All 'def' does is defines a new function. Consider it a shorthanded notation of 'definition'. Once you define a function, you give it a name. So let's say:
def newfunc(): [Remember that the parentheses are mandatory]
Now, you need to decide what you want the function to do. Let's say we want the function to print out "spam" (pretty standard), in that case we add:
def newfunc():
print("spam")
Finally, in order to execute this code in our project we simply call on the function as such:
newfunc()
0
def name():
print("lalala")
name
Output:
lalala