Python replace函数在windows10中不起作用

2024-06-29 00:16:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在运行适用于windows 3.8.0版的python。我可以运行下面的代码,它在我的Linux机器上运行良好,但在windows中不打印任何内容

a = "This is the island of istanbul"
b = a.replace("is" , "was")
print (b)

Tags: ofthe代码机器内容islinuxwindows
2条回答

我运行了代码,它运行得很好,只是它打印了“Thwas wasland of wastanbul”,除非这是要打印的。 如果您希望代码打印“This was the island of istanbul”,则需要在replace方法中添加空格

a = "This is the island of istanbul"
b = a.replace(" is ", " was ")
print(b)

看起来当我安装microsoftvisualstudio代码时,它也在不同的位置安装了自己的python版本

运行where.exe python get:

C:\Users\me\AppData\Local\Programs\Python\Python38-32.exe
C:\Users\me\AppData\Local\Microsoft\WindowsApps\python.exe

所以这一直是所有问题的根源

感谢用户eryk sun为我们提供的建议

相关问题 更多 >