After def, we write the name of our function (so as to invoke it later) and the names of…
Jump to turn (18)
- 1After def, we write the name of our function (so as to invoke it later) and the
- 2просто перевод задач
- 3After def, we write the name of our function (so as to invoke it later) and the
- 4In case you don't want to pass any arguments, the round brackets remain empty:
- 5You can also declare a sort of empty function with the pass statement:
- 6When you choose to call lazyfunc() with an arbitrary value as its argument, noth
- 7Parameters vs arguments It's not quite clear right now, what the parameters are,
- 8As you can see, this function is a reusable piece of code, which can be executed
- 9Execution and return Our previous function only performed some actions, but it d
- 10The keyword return is used to indicate what values the function outputs. Basical
- 11We declared the variable chant and invoked print(). Obviously, the function was
- 12Thus, we've learned the syntax for declaring functions. Now you also know that:
- 13What does a function return if it has no return statement in it?
- 14просто перевод задачи
- 15You are constructing a simple Python program that involves working with function
- 16Which of the following code snippets is the best way to declare a function that
- 17Define a function that will add the word "captain" before the name of a person.
- 18Define a function that will add the word "captain" before the name of a person.
- User
After def, we write the name of our function (so as to invoke it later) and the names of parameters, which our function can accept, enclosed in parentheses. Do not miss the colon at the end of the line. The names of a function and its parameters follow the same convention as variable names, that is, they should be written in lowercase with underscores between words.
An indent of 4 spaces shows the interpreter where the function's body starts and where it ends. All statements in the function's body must be indented. You can make calculations inside your function and use the return keyword to send the result back. Only when the indentation is absent, the definition of the function ends.
Later, the parameters take on values passed in a function call. Those values we pass to a function are known as arguments. The only distinction between parameters and arguments is that we introduce parameters in a function definition and give arguments (some specific values) in a function call. Here is a less abstract example of a function:
- Assistant