• Converts the first character of a string to uppercase and the remaining characters to lowercase.
  • Takes no parameters and returns a new string with the capitalized first character.
print('aBcD'.capitalize())
OUTPUT:
  • Returns a new string that is centered in a field of a specified width.
  • The original string is centered within the width, using spaces to pad the left and right sides as needed. The width parameter is the desired width of the new string, not including the padding characters.
print('['+'Hello, world!'.center(20)+']')
OUTPUT:
print('Hello, world!'.center(20,'*'))
OUTPUT:
  • Returns True if the string ends with the specified substring, otherwise False.
  • The substring parameter can be a string or a regular expression.
print('Hello, world!'.endswith('!'))
OUTPUT:
  • Returns the index of the first occurrence of the specified substring in the string, or -1 if the substring is not found.
  • The substring parameter can be a string or a regular expression.
print('Hello, world!'.find('world'))
OUTPUT:
  • Returns True if the string consists only of alphanumeric characters, otherwise False.
  • Alphanumeric characters are letters, numbers, and the underscore character.
print('ab123cd'.isalnum())
OUTPUT:
  • Returns True if the string consists only of alphabetic characters, otherwise False.
  • Alphabetic characters are letters from the English alphabet.
print('abcde'.isalpha())
OUTPUT:
  • Returns True if the string consists only of digits, otherwise False.
print('123456'.isdigit())
OUTPUT:
  • Returns True if the string consists only of lowercase characters, otherwise False.
print('hello'.islower())
OUTPUT:
  • Returns True if the string consists only of whitespace characters, otherwise False.
  • Whitespace characters are space, tab, newline, carriage return, and form feed.
print('   '.isspace())
OUTPUT:
  • Returns True if the string consists only of uppercase characters, otherwise False.
print('HELLO'.isupper())
OUTPUT:
  • Converts the iterable object (list, tuple, string) to a string by joining the elements with the specified separator.
  • The separator defaults to the empty string.
print(','.join(['a', 'b', 'c']))
OUTPUT:
  • Returns a new string with the leading whitespace characters removed.
  • The whitespace characters are determined by the isspace() method.
print('   hello'.lstrip())
OUTPUT:
  • Returns a new string with the specified substring replaced with the new substring.
  • The substring parameter can be a string or a regular expression. The new substring parameter can be a string or a regular expression.
print('Hello, world!'.replace('world', 'universe'))
OUTPUT:
  • Returns the index of the last occurrence of the specified substring in the string, or -1 if the substring is not found.
  • The substring parameter can be a string or a regular expression.
print('Hello, world!'.rfind('o'))
OUTPUT:
  • Returns a new string with the trailing whitespace characters removed.
  • The whitespace characters are determined by the isspace() method.
print('hello   '.rstrip()) 
OUTPUT:
  • Splits the string into a list of substrings based on the specified delimiter.
  • The delimiter defaults to the whitespace characters.
print('a,b,c'.split(',')) 
OUTPUT:
  • Returns True if the string starts with the specified substring, otherwise False.
  • The substring parameter can be a string or a regular expression.
print('Hello, world!'.startswith('Hello'))
OUTPUT:
  • Returns a new string with the leading and trailing whitespace characters removed.
  • The whitespace characters are determined by the isspace() method.
print('   hello   '.strip())
OUTPUT:
  • Converts all lowercase characters in the string to uppercase and all uppercase characters to lowercase.
  • Returns a new string with the swapped case characters.
print('hello'.swapcase())
OUTPUT:
  • Converts the first character of each word in the string to uppercase and the remaining characters to lowercase.
  • Returns a new string with the capitalized words.
print('hello world'.title())
OUTPUT:
  • Converts all lowercase characters in the string to uppercase.
  • Returns a new string with the uppercase characters.
print('hello'.upper())
OUTPUT: