注释与文档
'''Bad: Use lowercase letter at the beginning of a comment'''
# get user input
n,*vals=map(int,input().split())
'''Good: Always begin a comment with an uppercase letter'''
# Get user input
n, *vals = map(int, input().split())'''Bad: Ambiguous variable name with explanation'''
s = num1 + num2 # Sum of the two numbers
'''Good: Just use explanatory variable names without comments as explanation'''
sum_of_nums = num1 + num2'''Bad: Worthless comments'''
# Add num1 with num2 and assign the result to sum_of_nums
sum_of_nums = num1 + num2
'''Good: Just remove those useless comments'''
sum_of_nums = num1 + num2'''Worse: Misleading / Outdated comments'''
def process_nums(nums):
"""Return odd nums in the sequence."""
return filter(lambda num: num % 2 == 0, nums)
'''Good: Use correct / updated comments'''
def process_nums(nums):
"""Return even nums in the sequence."""
return filter(lambda num: num % 2 == 0, nums)Last updated