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

The reserved words for custom functions in python are

(*-*)浩
Release: 2019-08-21 11:11:23
Original
14541 people have browsed it

The reserved words for custom functions in python are

Basic usage(Recommended learning: Python video tutorial)

def function_name(parameters):
     expressions
Copy after login

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'
Copy after login

Running the program will give you the following output:

hello feather
hello csdn
Copy after login

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!')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template