str.maketrans (fromto [, to [, tonone]])
-> dict < /p>
da a: Unione [str | dict] - Se è presente un solo argomento, dovrebbe visualizzare numeri interi (rappresentazione Unicode) o stringhe (lunghe un carattere) in: numeri interi, stringhe o & # x27; Nessuno & # x27; - Supporto dizionario aggiunto in py3.0. Se & # x27; a & # x27; è specificato, è prevista una stringa (vedi sotto).
a: Optional [str] - Se specificato, strings & # x27; da a & # x27; e & # x27; a & # x27; deve essere della stessa lunghezza.
tonone: Optional [str] - + py3.0 La stringa di caratteri da sostituire con & # x27; Nessuno & # x27;.
Questo metodo di classe statica viene utilizzato per creare un dizionario (tabella) di sostituzione batch di caratteri in una stringa, che può essere passato al metodo str.translate () .
trans_table = str.maketrans ({
’ a’: ’b’ ,
’r’:’ t’,
’ z’: Nessuno,
})
# {97:’ b’, 114: ’t’, 122: Nessuno}
trans_table = str.maketrans (’ar’,’ bt’ , ’z’)
# {97: 98, 114: 116, 122: Nessuno}
’ arroz’.translate ( trans_table)
# ’btto’
Nota
Python 2 supportava solo due argomenti in attesa di stringhe.
Ci auguriamo che questo articolo ti abbia aiutato a risolvere il problema. Oltre a str.maketrans in Python, controlla altri argomenti relativi a Python functions.
Vuoi eccellere in Python? Consulta la nostra recensione dei migliori corsi online Python 2023. Se sei interessato alla scienza dei dati, controlla anche come imparare a programmare in R.
A proposito, questo materiale è disponibile anche in altre lingue:
- str.maketrans in Python
- Italiano str.maketrans in Python
- Deutsch str.maketrans in Python
- Français str.maketrans in Python
- Español str.maketrans in Python
- Türk str.maketrans in Python
- Русский str.maketrans in Python
- Português str.maketrans in Python
- Polski str.maketrans in Python
- Nederlandse str.maketrans in Python
- 中文 str.maketrans in Python
- 한국어 str.maketrans in Python
- 日本語 str.maketrans in Python
- हिन्दी str.maketrans in Python
Munchen | 2023-01-31
Forse ci sono altre risposte? Cosa significa esattamente str.maketrans in Python significa esattamente?. Spero solo che non emerga più
Tallinn | 2023-01-31
Forse ci sono altre risposte? Cosa significa esattamente str.maketrans in Python significa esattamente?. Non sono proprio sicuro che sia il metodo migliore
Shanghai | 2023-01-31
Mi stavo preparando per il mio colloquio di codifica, grazie per aver chiarito questo punto - str.maketrans in Python in Python non è il più semplice. Non sono proprio sicuro che sia il metodo migliore