前言:
本节将介绍如何自定义函数、调用函数、使用函数库中的函数
1、自定义函数
a、格式:def + 函数名(参数):
def hello_world(word):
注意,有colon冒号:
b、可选的函数注释"""Prints 'Hello World!' to the console."""
c、函数体
word = "Hello World!"
print(word)
整理上述代码如下:
def hello_world(word):
"""Prints 'Hello World!' to the console."""
word = "Hello World!"
print(word)
2、调用函数
函数名(参数)
helloworld("I love Python!")