Mètodes de cadenes a Python

De binefa.com
La revisió el 10:25, 9 ago 2024 per Jordi Binefa (discussió | contribucions) (Es crea la pàgina amb «Alguns dels mètodes que ofereixen les cadenes són: '''capitalize()''' – Canvia totes les lletres de cadena a majúscules. '''center()''' – centra la cadena din...».)
(dif) ← Versió més antiga | Versió actual (dif) | Versió més nova → (dif)
Salta a la navegació Salta a la cerca

Alguns dels mètodes que ofereixen les cadenes són:

capitalize() – Canvia totes les lletres de cadena a majúscules.

center() – centra la cadena dins del camp d'una longitud coneguda.

count() – compta el nombre de cops que hi apareix a una cadena un caràcter donat.

join() – joins all items of a tuple/list into one string; lower() – converts all the string's letters into lower-case letters; lstrip() – removes the white characters from the beginning of the string; replace() – replaces a given substring with another; rfind() – finds a substring starting from the end of the string; rstrip() – removes the trailing white spaces from the end of the string; split() – splits the string into a substring using a given delimiter; strip() – removes the leading and trailing white spaces; swapcase() – swaps the letters' cases (lower to upper and vice versa) title() – makes the first letter in each word upper-case; upper() – converts all the string's letter into upper-case letters.

2. String content can be determined using the following methods (all of them return Boolean values):

endswith() – does the string end with a given substring? isalnum() – does the string consist only of letters and digits? isalpha() – does the string consist only of letters? islower() – does the string consists only of lower-case letters? isspace() – does the string consists only of white spaces? isupper() – does the string consists only of upper-case letters? startswith() – does the string begin with a given substring?