04- calculates the number of characters -2

Calculating the length of the last word of the string, the words separated by a space.

Python  Split ()  is sliced by a string delimiter specified, the default for all null characters, including spaces, linefeed (\ n-), tab (\ t) and the like.

1 str1 = input()
2 ls1 = str1.split()
3 length = len(ls1[-1])
4 print(length)

 

Guess you like

Origin www.cnblogs.com/summer1019/p/11141204.html