What is a Python function definition? How to call?

  A Python function refers to a well-organized, reusable code segment used to implement a single or related function. The Python function includes some functions that come with the system, third-party functions, and user-defined functions. So what is the definition of a Python function? How to call it? Please see below for details.

  1. What is the function definition?

  A function is a block of code that can be reused. Use the keyword function to define a function.

  2. How to call the function?

  A function call is a function name plus parentheses, for example: function name (parameter [parameter optional])

  3. Notes on function definition

  1. The function code block starts with the def keyword, followed by the function identifier name and parentheses ()

  2. Any incoming parameters and independent variables must be placed between parentheses, which can be used to define parameters

  3. The first line statement of the function can optionally use the docstring—used to store the function description

  4. The function content starts with a colon and is indented

  5. return [expression] ends the function and optionally returns a value to the caller. return without an expression is equivalent to returning None

  4. Function summary

  function definition

  function function name (parameter [parameter optional]) {

  // code implementation of the function

  ...

  }

  function call

  function name (parameters [parameters optional])

Guess you like

Origin blog.csdn.net/oldboyedu1/article/details/132428773