Home  >  Article  >  Backend Development  >  The reserved words for custom functions in python are

The reserved words for custom functions in python are

(*-*)浩
(*-*)浩Original
2019-08-21 11:11:2314508browse

The reserved words for custom functions in python are

Basic usage(Recommended learning: Python video tutorial)

def function_name(parameters):
     expressions

Python uses def to start function definition , followed by the function name, inside the brackets are the parameters of the function, and inside are the specific function implementation codes of the function. If you want the function to have a return value, use return in the logic code in expressions.

Custom function

Creating a function is very simple, it uses the keyword (reserved word) "def", The code below Created a function with one parameter and called it with different parameters.

def hello(name):
    print('hello', name)

hello('feather')  # 调用函数,传入参数 'feather'hello('csdn')  # 调用函数,传入参数 'csdn'

Running the program will give you the following output:

hello feather
hello csdn

You can see that the parameters passed in are assigned to the variable name , and then execute the code block within the function, right! This is also a code block. Note that the colon

function does not have to have parameters. We can define a function without parameters, such as this

def hello():
    print('hello world!')

More Python related technical articles , please visit the Python Tutorial column to learn!

The above is the detailed content of The reserved words for custom functions in python are. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn