认识函数

# 函数
# print()

a = 3.14156
result = round(a,3)
print(result) # 3.142

python 内置了很多函数,你可能不了解某些函数的意思,那怎么办呢?

在python的命令行交互模式下,输入 help(函数名) 即可

➜  book-python git:(master) ✗ python3
Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help(round)

继续查看按return,退出q

函数有什么特点:

  1. 功能性
  2. 隐藏细节
  3. 避免编写重复的代码

results matching ""

    No results matching ""