Python:计算单词的长度

2024-09-29 08:26:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在有这个任务:

word = input("Please enter a word: ")

print("The length of " + word + " is " + len(word = int(word)))

它运行,我输入Lilith Qua

我遇到一个错误说:

^{pr2}$

有地方修理这个吗?在


Tags: oftheinputlenis错误lengthword
1条回答
网友
1楼 · 发布于 2024-09-29 08:26:50

在连接之前,必须将int转换为string。在

你必须使用

print("The length of " + word + " is " + str(len(word)))

字符串格式也可以用作

^{pr2}$

在这里

  • %s表示字符串

  • {/for

相关问题 更多 >