# 定义函数使用def def test(): """函数的注释""" print("hello python") test() # 调用函数 选中函数按ctrl + Q 可以查看函数注释
import hello # 引入函数文件 hello.test() # 调用引入的函数
# 传参 def test(num1,num2): a = num1+num2 return a result = test(10, 20) print(result)
# 函数的嵌套 def test(char, times): print(char * times) def test_s(num, char, times): """函数功能介绍 :param num: 循环输出多少次 :param char: 打印分割线使用的符号 :param times: 打印多少次 """ row = 0 while row < num: test(char, times) row += 1 test_s(10, "-", 20)
原文:https://www.cnblogs.com/dazahui/p/14848735.html