前面使用了源代码注释来指出文件名, 但注释还可用于在程序中添加各种说明,如文档、提示、解释或警告。Python 忽略所有注释,它们仅供你和其他可能阅读源代码的程序员阅读。 下面的示例程序演示了注释的其他一些用途: # coins_short.py # This program asks the user how many # coins of various types they have, # and then prints the total amount # of money in pennies. # get the number of nickels, dimes, # and quarters from the user n = int(input('Nickels? ')) d = int(input('Dimes? ')) q = int(input('Quarters? ')) # calculate the total amount of money total = 5 * n + 10 * d + 25 * q # print the results print() # prints a blank line print(str(total) + ' cents')