如何减去两个字符串? [英] How to subtract two strings?

查看:124
本文介绍了如何减去两个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长字符串,基本上是一个类似于 str = lamp,bag,mirror (和其他项目)

I have a long string, which is basically a list like str="lamp, bag, mirror," (and other items)

我想知道是否可以通过其他编程语言轻松地添加或减去某些项目: str = str- bag, 并得到 str = lamp,mirror, 在python中不起作用(我在W8 pc上使用2.7)

I was wondering if I can add or subtract some items, in other programming languages I can easily do: str=str-"bag," and get str="lamp, mirror," this doesnt work in python (I'm using 2.7 on a W8 pc)

是否可以将字符串拆分成 bag,并以某种方式将其用作减法?然后我仍然需要弄清楚如何添加。

Is there a way to split the string across say "bag," and somehow use that as a subtraction? Then I still need to figure out how to add.

推荐答案

您也可以这样做

print "lamp, bag, mirror".replace("bag,","")

这篇关于如何减去两个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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