String Methods in Python

SztringekSztring formázás

Strings come with many built-in methods that help you manipulate and check text. These methods return new strings – they don't change the original (strings are immutable).

We'll go through the most common ones with explanations and examples you can run right away.

Changing Case

These methods convert the string to uppercase, lowercase, title case (first letter of each word capitalized), or capitalize the first letter.

Trimming Whitespace

strip() removes whitespace from both ends, lstrip() from the left, and rstrip() from the right. This is useful when cleaning user input.

Replacing Text

replace() substitutes text. By default it replaces all occurrences, but you can limit the number of replacements.

Splitting and Joining

split() turns a string into a list by separating at a delimiter (default is whitespace). join() does the opposite – combines a list into a string using a separator.

Checking Content

These methods return True or False to check if a string starts/ends with something or contains only certain characters.

Finding Positions

find() returns the index of the first occurrence or -1 if not found. index() does the same but raises ValueError if not found.

Quick Quiz

Az anyagokat átnéztük és ellenőriztük, de hibák továbbra is előfordulhatnak. A tartalom kizárólag oktatási célt szolgál, ezért saját felelősségre használd, és szükség esetén ellenőrizd más forrásokkal is.

✨ Kérdezd Larát — a tanulási partnered

Fedezd fel a személyre szabott tanulási támogatást. Lara elmagyarázza az anyagot, összefoglalja a témákat és megválaszolja a kérdéseidet — az Go csomagtól elérhető.


Lara segít gyorsabban tanulni — kizárólag a ReadyTools Go, Plus és Max tagoknak.

Kövesd nyomon a fejlődésed 🚀

Tanulj egyszerűbben utad nyomonkövetésével teljesen ingyen.