当前位置:网站首页>The length of the last word of the string
The length of the last word of the string
2022-04-23 15:40:00 【Ye Ningxia Xin】
One 、 Calculate the length of the last word in the string
Title Description : Calculate the length of the last word in the string , Words are separated by spaces , String length is less than 5000.( notes : The end of the string does not end with a space )
Input description :
The input line , Represents the string to be evaluated , Non empty , The length is less than 5000.
Output description :
Output an integer , Represents the length of the last word of the input string .
Title source : Cattle from ( Huawei machine test )
Their thinking :
1. Get the input string , use input()
2. use if The function judges that the length of the string is less than and not empty
3. use strip(’ ') Remove the spaces that may be entered on the left and right sides
4. Use string to list function split( Specify split character ) Split the string into a list with spaces
5. Get the length of the last element of the list , Starting from the first character, the subscript is 0, In turn , Start with the last character , Subscript to be -1, Decrease in turn ,-2,-3....
words = input()
if len(words) <= 5000 and words is not None:
words = words.strip(' ')
word_list = words.split(' ')
print(len(word_list[-1]))
Two 、python strip() Methods use
python strip() Methods use _liff_lee The blog of -CSDN Blog _strip Method
3、 ... and 、split() Function introduction
split() Function introduction _ Rookie's Road -- Oh, my blog -CSDN Blog _split function
版权声明
本文为[Ye Ningxia Xin]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231534071722.html
边栏推荐
- IronPDF for . NET 2022.4.5455
- Upgrade MySQL 5.1 to 5.68
- Special analysis of China's digital technology in 2022
- fatal error: torch/extension.h: No such file or directory
- php函数
- 通过 PDO ODBC 将 PHP 连接到 MySQL
- Configuration of multi spanning tree MSTP
- Independent operation smart farm Innovation Forum
- YML references other variables
- Why disable foreign key constraints
猜你喜欢
随机推荐
Why disable foreign key constraints
一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
导入地址表分析(根据库文件名求出:导入函数数量、函数序号、函数名称)
Openstack command operation
Demonstration meeting on startup and implementation scheme of swarm intelligence autonomous operation smart farm project
MySQL Cluster Mode and application scenario
cadence SPB17.4 - Active Class and Subclass
c语言---字符串+内存函数
Summary of interfaces for JDBC and servlet to write CRUD
开源项目推荐:3D点云处理软件ParaView,基于Qt和VTK
群体智能自主作业智慧农场项目启动及实施方案论证会议
php类与对象
MySQL集群模式与应用场景
IronPDF for . NET 2022.4.5455
Educational codeforces round 127 A-E problem solution
Recommended search common evaluation indicators
Neodynamic Barcode Professional for WPF V11.0
Upgrade MySQL 5.1 to 5.66
【AI周报】英伟达用AI设计芯片;不完美的Transformer要克服自注意力的理论缺陷
How to test mobile app?








