简体   繁体   中英

Python replace function doesn't work in Windows 10

I'm currently running python for windows version 3.8.0. I can run the code below and it works fine on my Linux machine but doesn't print out anything in windows.

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

I ran the code and it worked fine, except it printed "Thwas was the wasland of wastanbul", unless that's what's intended to be printed. If you want the code to print "This was the island of istanbul" you would need to add spaces on your replace method.

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

Looks like when i installed Microsoft Visual Studio Code it also installed it's own version of python in a different location.

Running where.exe python i get:

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

So that was causing all the problems all along.

Thanks to user eryk-sun for suggesting what to look for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM