I am looking for a Python expression that would transform this chunk of text:
z= 10
zi = 300
print(z)
print(z * 180)
print(z - 3241)
y=z
print(type(z))
print(type(y))
print(type(z[0]))
print(type(z[1]))
into the following chunk of text:
K= 10
zi = 300
print(K)
print(K * 180)
print(K - 3241)
y=K
print(type(K))
print(type(y))
print(type(K[0]))
print(type(K[1]))
I have tried:
newdata = filedata.replace("z", "K")
But, this replaces all instances of z
, whereas I would only like to replace words whose only letters are z
.