Python 中的软件工程原理
Adam Spannbauer
Machine Learning Engineer at Eastman
# 计算 x 的平方
"""计算 x 的平方
:param x: 要求平方的数
:return: x 的平方
>>> square(2)
4
"""
# 这是有效的注释
x = 2
y = 3 # 这也是有效的注释
# 除非查看源代码,否则你看不到我# 你好,未来的协作者!
注释"做什么"
# 将 people 定义为 5
people = 5
# 将 people 乘以 3
people * 3
注释"为什么"
# 将有 5 个人参加聚会
people = 5
# 每人需要 3 片披萨
people * 3
def function(x):
"""函数的高级描述
函数的更多细节
def function(x):
"""函数的高级描述
函数的更多细节
:param x: 参数 x 的说明
:return: 返回值的说明
def function(x):
"""函数的高级描述
函数的更多细节
:param x: 参数 x 的说明
:return: 返回值的说明
>>> # 函数用法示例
示例用法的期望输出
"""
# 函数代码
def square(x):
"""计算 x 的平方
:param x: 要求平方的数
:return: x 的平方
>>> square(2)
4
"""
# `x * x` 比 `x ** 2` 更快
# 参考: https://stackoverflow.com/a/29055266/5731525
return x * x
help(square)
square(x)
计算 x 的平方
:param x: 要求平方的数
:return: x 的平方
>>> square(2)
4
Python 中的软件工程原理