Python de type Str n'a pas de fonction inverse.
Cependant, en inversant les tranches, nous pouvons inverser efficacement une chaîne.
Seuls les caractères anglais sont pris en charge.
Exemple :
1 2 3 4 | <span style= "color: #008080" >1</span> a = <span style= "color: #800000" > '</span><span style="color: #800000">example</span><span style="color: #800000">' </span>
<span style= "color: #008080" >2</span> b = a[::-1<span style= "color: #000000" >]
</span><span style= "color: #008080" >3</span> <span style= "color: #0000ff" > print </span><span style= "color: #000000" >(b)
</span><span style= "color: #008080" >4</span> <span style= "color: #008000" >#</span><span style= "color: #008000" >输出结果 'elpmaxe' </span>
|
Copier après la connexion
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!