Computer Science, asked by sharanya7649, 1 year ago

Remove characters from the first string which are present in the second string

Answers

Answered by Equestriadash
6

s1 = input("Enter a string: ")

s2 = input("Enter a second string: ")

new_str = ""

for i in s1:

 if i not in s2:

   new_str = new_str + i

print(new_str, "is the result.")

You'll need to assign an empty string in order to do this.

Once the loop starts, and its checking for the characters, the empty string gets added along with the values i takes, provided it satisfies the condition of the characters in s2 being in s1.

An empty string is a string that has no characters. It can be declared by simply assigning quotes to a variable.

It must not be mistaken for " ".

" " and "" are both different. " " has space, which is counted as a character, whereas "" has no character.

Attachments:
Similar questions