python算法集锦【二】

题目描述

计算字符串最后一个单词的长度,单词以空格隔开。

输入描述:

一行字符串,非空,长度小于5000。

输出描述:

整数N,最后一个单词的长度。

输入

hello world

输出

5

1 import sys
2 strs = sys.stdin.readline()
3 print(len(strs.split()[-1]))

 

原文地址:https://www.cnblogs.com/tython/p/12751350.html