python 练习题-字符串最后一个单词的长度

题目链接:https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da?tpId=37&tqId=21224&rp=1&ru=%2Fta%2Fhuawei&qru=%2Fta%2Fhuawei%2Fquestion-ranking&tab=answerKey

 1 # @Author  :whyCai
 2 # @Time    :2021/3/31 21:26
 3 
 4 
 5 """
 6 计算字符串最后一个单词的长度,单词以空格隔开。
 7 
 8 输入描述:
 9 输入一行,代表要计算的字符串,非空,长度小于5000。
10 
11 输出描述:
12 输出一个整数,表示输入字符串最后一个单词的长度。
13 
14 示例1
15 输入
16 hello nowcoder
17 输出
18 8
19 """
20 #以空格分割输入的字符串,输出最后一个值长度
21 s = input().split()
22 print(len(s[-1]))

原文地址:https://www.cnblogs.com/whycai/p/14603912.html