๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

Remove the given word

โ† All Python Programs

Aim:

☛   Remove the given word in all the places in a string?

Solution :


PROGRAM: (remove_words.py)

 
def remove_all_words(in_str,sub):
	my_list = in_str.split( )
	for i in my_list :
		if i == sub :
			del my_list[my_list.index(i)]
	final_string = ' '
	for i in my_list :
		final_string = final_string + i + ' '
	return final_string
str_in = input(" Enter any string = ")
sub = input(" Enter sub string ( which word you want to delete ) = ")
result = remove_all_words(str_in , sub)
print(" Updated string after removal sub_string : \n " , result)

OUTPUT:

 
 Enter any string = Hai, this is python, welcome to Study Glance
 Enter sub string ( which word you want to delete ) = Study
 Updated string after removal sub_string :
   Hai, this is python, welcome to Glance


๐Ÿ’ป Run This Python Program

Remove the given word
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals