“Usuń interpunkcję sznurka Python 3” Kod odpowiedzi

Usuń interpunkcję z Python strun

#with re
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
#without re
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))
Bad Buffalo

interpunkcja paska Python3 z sznurka

import string
#make translator object
translator=str.maketrans('','',string.punctuation)
string_name=string_name.translate(translator)
Breakable Buffalo

Python Usuń interpunkcję ze sznurka

# Python program to remove punctuation from a string

import string
text= 'Hello, W_orl$d#!'

# Using translate method
print(text.translate(str.maketrans('', '', string.punctuation)))
Gorgeous Gazelle

Usuń interpunkcję sznurka Python 3

import string 
sentence = "Hey guys !, How are 'you' ?"
no_punc_txt = ""
for char in sentence:
   if char not in string.punctuation:
       no_punc_txt = no_punc_txt + char
print(no_punc_txt);                 # Hey guys  How are you 
# or:
no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
print(no_punc_txt);                 # Hey guys  How are you 
VasteMonde

Odpowiedzi podobne do “Usuń interpunkcję sznurka Python 3”

Pytania podobne do “Usuń interpunkcję sznurka Python 3”

Więcej pokrewnych odpowiedzi na “Usuń interpunkcję sznurka Python 3” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu