首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从字符串Python中提取值

从字符串Python中提取值
EN

Stack Overflow用户
提问于 2019-05-10 01:53:25
回答 4查看 4.8K关注 0票数 0

处理机器人应用程序,所以我需要从消息字符串中提取值,并将其传递给一个变量。消息字符串可以采用不同的方式,例如:

代码语言:javascript
复制
message = 'name="Raj",lastname="Paul",gender="male", age=23'
message = 'name="Raj",lastname="Paul",age=23'
message = 'name="Raj",lastname="Paul",gender="male"'

用户提供的数据可以包含所有值,或者有时会缺少年龄或性别字段。

我被卡住的地方是,I am not sure how to check if age is present in the message text. If it is then extract value corresponding to age. If age is not in message, ignore age.

可以检查循环中的每个单词并提取字符串,但它会变得相当长。如果有更简单的方法,请告诉我

喜欢

代码语言:javascript
复制
if Age is present in message then get the value of age,
if lastname is present in message then get the value of lastname
if gender is present in message then get the value of gender
if name is present in message then get the value of name
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56065023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档