Strings: Sequence of characters identified by specific index starting from zero.
Definition: Substring extraction using slice notation string[start:end]
with start
inclusive and end
exclusive.
Examples:
my_string[0:2]
-> "He"
my_string[7:10]
-> "Wor"
New String Objects: Slicing creates new strings (e.g., animal = my_string[4:7]
).
Missing End Index: my_string[8:]
extracts till the end.
Negative Indices: Count from the end of the string (e.g., my_string[-5]
).
Definition: string[start:end:stride]
allows index increments (e.g., my_string[0:9:2]
).
Replace: string.replace(old, new, count)
for substring replacement.
Find Methods: find(substring)
locates first occurrence; count(substring)
counts occurrences.
Membership: Use in
to check for substring presence.
Lexicographical Order: Based on ASCII values (e.g., "y" > "a"
).
Methods: isalpha()
, isdigit()
, islower()
, isupper()
, isspace()
for various checks.
Formatting: strip()
for whitespace, capitalize()
for first letter, and title()
to capitalize each word.