str relace method confusion
Question:
x=["a = 1;","b = input();","if a + b > 0 && a - b < 0:"]
for i in range(len(x)):
y = x[i]
y.replace(" && ", " and ")
y.replace(" || ", " or ")
print(y)
This code is suppose to print
a = 1;
b = input();
if a + b > 0 and a - b < 0:
but I am getting result which corresponds to replace method not working. I have tried this on colab as well as jupiter notebook.
a = 1;
b = input();
if a + b > 0 && a - b < 0:
Answers:
Strings in Python cannot be modified. The replace
function returns a new string with the change.
y = y.replace(" && ", " and ")
y = y.replace(" || ", " or ")
Which can, of course, be combined into one statement.
x=["a = 1;","b = input();","if a + b > 0 && a - b < 0:"]
for i in range(len(x)):
y = x[i]
y.replace(" && ", " and ")
y.replace(" || ", " or ")
print(y)
This code is suppose to print
a = 1;
b = input();
if a + b > 0 and a - b < 0:
but I am getting result which corresponds to replace method not working. I have tried this on colab as well as jupiter notebook.
a = 1;
b = input();
if a + b > 0 && a - b < 0:
Strings in Python cannot be modified. The replace
function returns a new string with the change.
y = y.replace(" && ", " and ")
y = y.replace(" || ", " or ")
Which can, of course, be combined into one statement.