String methods in Python

capitalize()Change to upper case for the first char
center()Center the string by using filling chars
casefold()Change to lower case for all upper case chars in a string
count()Counting Presence of sub string inside main string
endswith()Checking if string ends with input string
expandtabs()Checking if string ends with input string
find()Case sensitive string search
index()Case sensitive string search
isalnum()Check if all chars are alphanumeric in a string
isalpha()Check if all chars are alphabets in a string
isdecimal()Check if all chars are decimal numbers in a string
isdigit()Check if all chars are digits in a string
isidentifier()Check if the string is identifier
islower()Check if all chars are lower case only
isnumeric()Check if all chars are numeric
isprintable()Check if all chars are printable or not
isspace()Check if all chars are whitespace or not
istitle()Check if all words starts with upper case letters
isupper()Check if all chars are upper case letters
join()Join elements of a iterable object
ljust()Left Justifying the string
lower()Change all upper case to lower case chars
lstrip()Removes space or char from left side of the string
partition()Breaking string by using search word
replace()search and replace string inside a main string
rfind()search from right and returns the position of the matching string
rindex()search from right and returns the position of the matching string
rjust()Right Justify the string
rpartition()Breaking string by using search word from right
rsplit()Breaking string by using delimiter
rstrip()Removing chars from right side
split()Split the string using delimiters
splitlines()Break the string using line breaks
startswith()Check if string is starting with or not
strip()Remove space or char from left or right of the string
swapcase()Change case from lower to upper and upper to lower
title()First char of each word to upper case letter
translate()Mapping chars of a string
upper()Change all lower case to upper case letter
zfill()fill the left of the string with zeros
regular experssionExtracting date from a string
  1. Exercise on String methods
  2. Display one input string after adding x zeros, where x is equal to half of the length of the string
  3. Read one html page ( use one sample page ) and display the content written inside different tags like <Title>, <Description>, <keyword>, <body> etc . ( View source of any web page will show you different tags )
    You can use sample html page here
  4. What is the difference between rfind() and rindex()
  5. Input string is 'Welcome to'. Replace the .com with .net
  6. Find out the number of occurrence ( frequency ) of each chars in a string
  7. Create a string by using first two chars , last two chars and middle two ( or three based on centre ) chars of a input string.
  8. From one input string, char with highest occurrence ( frequency ) should be replaced by its number of occurrence
  9. Take one input string and generate error message if any special char including space is present. Under score is allowed. Add extension of .com to this string and display.
  10. Arrange one input string in such a way that Upper case letters should come first
  11. Change to upper case all the chars at even index position
  12. Collect the following details . Title , description, keywords , body , H1, Details and then create one html page and save as my_name.html
  13. Insert second string at the centre of the first string
  14. Create Caesar encryption of an input string
  15. Convert first n chars to upper case
  16. Find out the first repeated char in a string
  17. Change to upper case char for all first and last char of words present inside a string
  18. Count number of special chars, upper case , lower case and numbers present in a string
  19. Collect the integer part from the string.
    Input = I joined college at 18 years of age
    Output = 18
Python if else for loop

Post your comments , suggestion , error , requirements etc here

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 All rights reserved worldwide Privacy Policy Disclaimer