相关疑难解决方法(0)

除非分配输出,否则为什么不调用Python字符串方法呢?

我尝试做一个简单的字符串替换,但我不知道为什么它似乎不起作用:

X = "hello world"
X.replace("hello", "goodbye")
Run Code Online (Sandbox Code Playgroud)

我想将单词更改hellogoodbye,因此它应该将字符串更改"hello world""goodbye world".但X仍然存在"hello world".为什么我的代码不起作用?

python string replace

133
推荐指数
1
解决办法
10万
查看次数

删除字符串中的所有引号

  • 我只想从字符串中删除所有引号。
  • 我试过使用.strip()和 for 循环,但也不起作用。
  • 我究竟做错了什么?
  • 我知道这个问题与堆栈溢出的其他一些问题类似,我看了他们,他们没有给我一个直接的答案。
string = """Hi" how "are "you"""
string.replace('"',"")
print(string)
Run Code Online (Sandbox Code Playgroud)

python string

-3
推荐指数
1
解决办法
103
查看次数

标签 统计

python ×2

string ×2

replace ×1