Python中print用法里面% ,"%s 和 % d"格式操作符
其中:
#%.2f格式化操作符,表示保留两位小数,不够2位不需要补0
print('REVERSE METHOD: Elapsed time: %.2f seconds' % elapsed_time)
animal_list = ['dog', 'cat','fish','pony','parrot','leopard','frog','mouse','snake']
#index%9表示列表中的9个数依次选出
answer = input('Would you like to adopt a '+ animal_list[index%9]+ '? [Y/N]')
结果:
Would you like to adopt a dog? [Y/N]
Would you like to adopt a cat? [Y/N]
……
转自https://blog.csdn.net/qq_37482544/article/details/63720726