Python List Methods

MethodDescription
capitalize()Converts the first character to upper case.
casefold()Converts string into lower case.
center()Returns a centered string.
count()Returns the number of times a specified value occurs in a string.
encode()Returns an encoded version of the string.
endswith()Returns true if the string ends with the specified value.
expandtabs()Sets the tab size of the string.
find()Searches the string for a specified value and returns the position of where it was found.
format()Formats specified values in a string.
index()Searches the string for a specified value and returns the position of where it was found.
join()Joins the elements of an iterable to the end of the string.
lower()Converts a string into lower case.
lstrip()Returns a left trim version of the string.
partition()Returns a tuple where the string is parted into three parts.
replace()Returns a string where a specified value is replaced with a specified value.
splitlines()Splits the string at line breaks and returns a list.
startswith()Returns true if the string starts with the specified value.
strip()Returns a trimmed version of the string.
swapcase()Swaps cases, lower case becomes upper case and vice versa.
title() Converts the first character of each word to upper case.
translate()Returns a translated string.
upper()Converts a string into upper case.

capitalize() Method

The capitalize() method returns a string where the first character is upper case, and the rest is lower caser<> Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter,
while making all other characters in the string lowercase letters.
It is simply known as to convert letters from upper case letterss to lower case letters vice versa.

a="hello RGUKT"
b=a.capitalize()
print(b)

casefold() Method

The casefold() method converts all characters of the string into lowercase letters and returns a new string.
Python String casefold() method is used to convert string to lower case. It is similar to lower() string method,but case removes all the case distinctions present in a string.

a="PYThoN"   #string containing lower and upper case leters
b=a.casefold()
print(b)    #out put is python

center() Method

Python String center() method creates and returns a new string that is padded with the specified character.
Python String center() Method tries to keep the new string length equal to the given length value and fills the extra characters using the default character (space in this case).
The center() method returns a new centered string after padding it with the specified character.

a="this is python"   #this string containng alphabets and space
b=a.center(24,'*')
print(b)     #Output is ***this is python*** 
count() Method

The count() method returns the number of occurrences of a substring in the given string.
Python String count() function is an inbuilt function in python programming language that returns the number of occurrences of a substring in the given string

a="hello rguktians form rgukt"
b=a.count('r')      #counting number of 'r' in given string
print(b)     #Output is 3

encode() Method

The encode() method returns an encoded version of the given string.
Python String encode() converts a string value into a collection of bytes, using an encoding scheme specified by the user.

a="this is python"
b=a.encode()
print(b)    #Output is b'this is python'

endswith() Method

The endswith() method returns True if a string ends with the specified suffix. If not, it returns False.
Python String endswith() method returns True if a string ends with the given suffix, otherwise returns False.

a="this is rgukt"
b=a.endswith('rgukt')    # checking given string is ends with 'rgukt' whether it is true or false
print(b)     # Output is True

expandtabs() Method

The expandtabs() method returns a copy of string with all tab characters '\t' replaced with whitespace characters until the next multiple of tabsize parameter.

a="this \t is \t rgukt"
b=a.expandtabs()
print(b)     #Output is this   is   rgukt 

find() Method

Python String find() method returns the lowest index or first occurrence of the substring if it is found in a given string.
If it is not found, then it returns -1.

a="hello rguktians this is rgukt web"
b=a.find('this')
print(b)        # Output is 16

format() Method

The string format() method formats the given string into a nicer output in Python.
Python string format() function has been introduced for handling complex string formatting more efficiently.
Sometimes we want to make generalized print statements in that case instead of writing print statement every time we use the concept of formatting.

a="this is code of formate in {}"
print(a.format("strings"))       # Output is 'this is code of formate in strings'

index() Method

Python String index() Method allows a user to find the index of the first occurrence of an existing substring inside a given string.
The index() method returns the index of a substring inside the string (if found).
If the substring is not found, it raises an exception.

a="this is from rgukt web"
b=a.index('from')
print(b)       #Output is '8'

join() Method

join() is an inbuilt string function in Python used to join elements of the sequence separated by a string separator.
This function joins elements of a sequence and makes it a string.
The join() method takes all items in an iterable and joins them into one string.
A string must be specified as the separator.

a = ['R','G','U','K','T']
print("".join(list1))        #Output is 'RGUKT'

lstrip() Method

Python String lstrip() method returns a copy of the string with leading characters removed (based on the string argument passed).
If no argument is passed, it removes leading spaces.

a="      rgukt srikakulam"      #string containg left space
print(a.lstrip())           #Output is 'rgukt srikakulam'

lower() Method

Python String lower() method converts all uppercase characters in a string into lowercase characters and returns it.
In this article, we will cover how to convert uppercase to lowercase in Python.

a="RguKt SrIkakUlAm"     # string contains both upper and lower case alphabets
b=a.lower()
print(b)              # Output is 'rgukt srikakulam'

partition() Method

Python String partition() method splits the string at the first occurrence of the separator and returns a tuple containing the part before the separator, separator and the part after the separator.
Here, the separator is a string that is given as the argument.

c="this is rguktweb from rgukt sklm"
print(c.partition("from"))         #Output is ('this is rguktweb ', 'from', ' rgukt sklm') 

replace() Method

The replace() in Python returns a copy of the string where all occurrences of a substring are replaced with another substring.

a="rgekt"
b=a.replace("e","u")
print(b)        #Output is 'rgukt'

splitlines() Method

Python String splitlines() method is used to split the lines at line boundaries.
The function returns a list of lines in the string, including the line break(optional).

a="this is rgukt web \r from \n rgukt sklm"
print(a.splitlines())      #Output is ['this is rgukt web', ' from', ' rgukt sklm'] 

startswith() Method

Python String startswith() method returns True if a string starts with the specified prefix (string).
If not, it returns False.

a="this is rgukt web"
print(a.startwith("this"))      #Output is True
print(a.startwith("rgukt"))      #Output is False

strip() Method

strip() is an inbuilt function in Python programming language that returns a copy of the string with both leading and trailing characters removed (based on the string argument passed).

a="rgukt web from rgukt"
print(a.strip('rgukt'))       #Output is web from

swapcase() Method

The string swapcase() method converts all uppercase characters to lowercase and vice versa of the given string, and returns it.

a="this is RguKt Web froM RguKt SkLm"
b=a.swapcase()
print(b)        #Output is 'THIS IS rGUkT wEB FROm rGUkT sKlM'

title() Method

The String title() method in Python is used to convert the first character in each word to uppercase and the remaining characters to lowercase in the string and returns a new string.

a="this is rgukt web team"
b=a.title()
print(b)     #Output is 'This Is Rgukt Web Team'

translate() Method

translate() returns a string that is modified string of givens string according to given translation mappings.



upper() Method

upper() method converts all lowercase characters in a string into uppercase characters and returns it.

a="This is rGukt web Team from RGukt"
b=a.upper()
print(b)       #Output is 'THIS IS RGUKT WEB TEAM FROM RGUKT'