从python中的字符串打印一个单词 [英] Print one word from a string in python

查看:94
本文介绍了从python中的字符串打印一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 python 中只打印字符串中的某些单词?假设我只想打印第 3 个单词(这是一个数字)和第 10 个单词

How can i print only certain words from a string in python ? lets say i want to print only the 3rd word (which is a number) and the 10th one

虽然每次的文本长度可能不同

while the text length may be different each time

mystring = "您有 15 条新消息,大小为 32000"

谢谢.

推荐答案

mystring = "You have 15 new messages and the size is 32000"
parts = mystring.split(' ')
message_count = int(parts[2])
message_size = int(parts[9])

这篇关于从python中的字符串打印一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆