Advertisement



< Prev
Next >



Python - String Methods




Some methods of String class

In the table below, we have given a short preview about some important built-in methods available to string objects. You may click on the name of method to get a detailed description with an example.


Advertisement




Methods Description
capitalize()
This method converts only the first character of a string to uppercase.

upper()
This method converts a string to uppercase.

isupper()
This method returns true if all the characters in it are uppercase.

title()
This method converts each first alphabet of a word in a string to uppercase.

istitle()
This method returns true if the invoked string has followed the rules of a naming a title.

casefold()
This method converts a string to lowercase.

lower()
This method converts a string to lowercase.

islower()
This method returns true if all the characters in it are lowercase.

swapcase()
This method swap cases of characters in a string, i.e. from lowercase to uppercase or from uppercase to lowercase.

lstrip()
This method trims/removes all the whitespace from the left of the string.

rstrip()
This method trims/removes all the whitespace from the right of the string.

strip()
This method trims/removes all the leading and trailing whitespace from the string.

isspace()
This method return true, if all the characters in the invoked string are whitespaces.

isnumeric()
This method return true, if all the characters in the invoked string are numeric.

isdigit()
This method return true, if all the characters in the invoked string are digits.

isalpha()
This method return true, if all the characters in the invoked string are alphabets.

isalnum()
This method return true, if all the characters in the invoked string are alphanumeric.

isdecimal()
This method return true, if all the characters in the invoked string are decimals.

isidentifier()
This method return true, if string is an identifier.

isprintable()
This method return true, if all the characters in the invoked string are printable.

startswith()
This method returns true if the invoked string starts with a specific value.

endswith()
This method returns true if the invoked string ends with a specific value.

index()
This method returns us the index of the first occurrence of a value found in a string.

find()
This method returns us the index of the first occurrence of a value found in a string.

rfind()
This method returns us the index of the last occurrence of a value in a string.

rindex()
This method returns us the index of the last occurrence of a value in a string.

center()
This method returns us a centered version of the invoked string.

rjust()
This method returns a right justified version of the invoked string.

ljust()
This method returns a left justified version of the invoked string.

replace()
This method replaces all the occurrences of a particular character with a specific character in the string.

count()
This method counts the number of times a value has occured in the invoked string.

split()
This method is used split the string at the first occurrence of a specificseparator and returns a list.

rsplit()
This method is used split the string at the last occurrence of a specificseparator and returns a list.

splitlines()
This method is used split the string at line breaks and returns a list.

partition()
This method searches the first occurrence of specific value in a string and partitions the string into a tuples of 3 strings.

rpartition()
This method searches the last occurrence of specific value in a string and partitions the string into a tuples of 3 strings.

zfill()
This method fills a string with a specific number of zeros i.e. 0, at the beginning of a string.




Please share this article -





< Prev
Next >
< Python - String
String capitalize() Method >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement