Knowledge Card - String Methods
String Methods
-
len(): Returns the length of a string.
- Example:
len('hello')
returns5
.
- Example:
-
upper(): Converts all characters to uppercase.
- Example:
'hello'.upper()
returns'HELLO'
.
- Example:
-
lower(): Converts all characters to lowercase.
- Example:
'HELLO'.lower()
returns'hello'
.
- Example:
-
replace(): Replaces occurrences of a substring with another.
- Example:
'hello world'.replace('world', 'there')
returns'hello there'
.
- Example:
-
split(): Splits a string into a list based on a delimiter.
- Example:
'apple,banana,cherry'.split(',')
returns['apple', 'banana', 'cherry']
.
- Example: