How to Remove Specific Character from String in Python – GATE, Interview & Placement Practice
85 views
Jun 1, 2025
Get the full source code of application here:
View Video Transcript
0:00
uh hello guys welcome to this video So
0:01
in this video I will show you a very
0:03
common program which is asked inside
0:05
Python interviews placements and uh
0:08
placements as well So whether how to
0:10
remove a particular character from a
0:12
sentence So let me show you this program
0:14
that I written inside Python step by
0:17
step So let's suppose you have a uh
0:20
sentence or a string placement
0:23
preparation If you want to specifically
0:26
remove some characters from the sentence
0:28
let's suppose I want to remove this e
0:31
character which is appearing here also
0:34
here also So how to do this it's very
0:37
simple So you can put any character
0:40
Let's suppose I want to remove P here So
0:43
this is character to remove So you can
0:46
remove P
0:49
character here
0:51
also So this will be the output coming
0:53
So for doing this we simply declare one
0:56
more variable result which will hold the
0:58
result for us and then we simply use the
1:01
for loop character by character and here
1:04
we will be comparing each character
1:06
right here in the index array index So
1:09
here the first character is P So this is
1:12
the exact character that we want to
1:14
remove So this character will be ignored
1:17
This will not be added in the result So
1:19
it will move to the next iteration next
1:22
character in the line which is L L is
1:24
not equal to P So L will be added in the
1:27
result As you can see it will go step by
1:31
step and uh only remove the P character
1:34
when it comes with P So as you can see
1:37
again P comes it will remove it or it
1:40
will ignore it It will not add this come
1:44
just do it like this
1:48
So in this easy way you can remove
1:51
certain characters from your string very
1:54
easily and uh explain this to the
1:58
interviewer It's a beginner friendly
2:01
program It's very simple to do You
2:03
define a variable that you want to
2:04
remove and then simply apply for loop
2:07
character by character Simply compare it
2:10
and then you have the output
2:14
So thank you very much guys for watching
2:16
this video and also check out my website
2:19
freemediatools.com
2:21
uh which contains thousands of tools
#Computer Education
#Education
#Scripting Languages