Python String Methods
Python String Methods
upper()
The upper() method converts all lowercase letters in a string to upper
Syntax:
string.upper()
Example:
text = 'hello'
result = text.upper() # Output: 'HELLO'
2. lower()
The lower() method converts all uppercase letters in a string to lowerc
Syntax:
string.lower()
Example:
text = 'HELLO'
result = text.lower() # Output: 'hello'
3. strip()
The strip() method removes any leading and trailing whitespace from a
Syntax:
string.strip()
Example:
text = ' hello '
result = text.strip() # Output: 'hello'
4. replace()
The replace() method replaces a substring with another substring in a s
Syntax:
string.replace(old, new)
Example:
text = 'hello world'
result = text.replace('world', 'Python') # Output: 'hello Python'
5. split()
The split() method splits a string into a list of substrings based on a deli
Syntax:
string.split(delimiter)
Example:
text = 'a,b,c'
result = text.split(',') # Output: ['a', 'b', 'c']