How to Remove Punctuation from String in Python – GATE, Interview & Placement Practice
41 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:02
in this program i will show you a very
0:04
common program which is asked whether to
0:07
remove a punctuation from your sentence
0:10
so it is asked inside interviews python
0:12
interviews placements as well so this is
0:15
actually the program punctuations are
0:17
nothing but full stop dot comma
0:20
everything so if you want to remove
0:23
everything from your sentence so we give
0:25
this input sentence right here this is
0:27
our sentence hello world it's a
0:29
beautiful day you see all these
0:31
punctuations which are this is your
0:32
comma this is your exclamation mark this
0:35
is your this comma again dot symbol all
0:39
these punctuations you don't want so you
0:41
can actually remove all these
0:42
punctuations first of all we define a
0:44
variable which hold all these
0:46
punctuations you can see we predefined
0:49
all these punctuations in a variable so
0:52
now we will simply run a simple for loop
0:55
removing one by one comparing each
0:58
character whether it's equal to this
0:59
punctuation or not and then we create
1:02
another variable which will hold the
1:05
output sentence for us which is no
1:06
punctuation it's empty by default and
1:09
now we are simply using the for loop and
1:12
we are going character by character so
1:14
we are simply putting the first
1:15
character which is h so h is not equal
1:18
to this defined right here so it will
1:21
neglect it will come to the next
1:23
character it will add
1:25
this e is also not there l will also be
1:30
added you can see
1:32
that it will take each character now we
1:35
get this comma comma is present right
1:37
here if you see comma is present it will
1:40
be ignored so this will not be
1:43
added you can see
1:45
that space is not there so it will be
1:51
added so in this easy way you can see
1:53
that all the characters which are
1:56
defined in the punctuations will be
1:58
ignored and uh rest of the sentence will
2:01
remain constant and you will get your
2:02
output in the no punctuation so this is
2:05
the actual control of the program which
2:07
will be there and you will get your
2:09
output like this so all the logic is
2:14
done inside this for loop and we
2:17
predefined all your punctuations in this
2:19
variable and then we simply run this for
2:21
loop character by character then do this
2:24
uh thank you very much guys for watching
2:26
this video and also check out my website
2:29
freemediatools.com
2:31
uh which contains thousands of tools
#Computer Education
#Scripting Languages