formatting是格式的意思,再看看代码发现
print('There are &d letters, %d spaces, %d digits and %d other characters in your string.' %(letter,space,digit,other))
letters前面的%d写成了&d
python中%d表示格式化一个对象为十进制整数,使用后,在需要输出的长字符串中占位置。输出字符串时,可以依据变量的值,自动更新字符串的内容。
formatting是格式的意思,再看看代码发现
print('There are &d letters, %d spaces, %d digits and %d other characters in your string.' %(letter,space,digit,other))
letters前面的%d写成了&d
python中%d表示格式化一个对象为十进制整数,使用后,在需要输出的长字符串中占位置。输出字符串时,可以依据变量的值,自动更新字符串的内容。