Python String Methods

15-01-23 Ahmed Obaid 2030 0

Python provides a lot of built-in functions for manipulating strings. String in Python is immutable, so all these functions return a new string and the original string remains unchanged. You do not have to memorize all of these functions that we will mention in this article. All you have to know is how to use these functions and what they can do. All of these functions are present by default in the str class inside the builtins.py file, which is included in the Python interpreter. 























































































name description URL
capitalize() The capitalize() function returns a new copy of the original string and converts the first character of the string to a capital letter, while all other characters in the string are lowercase. read more 
upper()  The upper() function converts all lowercase letters in a string to uppercase and returns. But do not deal with symbols and numbers. read more 
lower()  The lower() function is a built-in function that is mainly used to manipulate strings. Converts text strings written in lowercase letters to uppercase letters. If read more 
center()  The center() function creates and returns a new string with the specified character inside it. If no specified character is provided, it returns a new string, adding, by default, blank spaces. read more 
title()  The title() function converts the first letter of each word to uppercase and the remaining letters to lowercase. and returns a new string. read more 
istitle()  istitle() returns True if the string is a title. otherwise it returns False. read more 
rjust()  The rjust() function returns a new copy of the original string with the padding character passed to the 'character' from the left. If no character is passed in the 'character' argument, blank white spaces will be added. With a number passed to the length argument to specify the total number of characters for the string. read more 
ljust()  The ljust() function returns a new copy of the original string with the fill character added to the 'character' argument from the right. If no character is passed in the 'character' argument, blank white spaces will be added. With a number passed to the length argument to specify the total number of characters for the string. read more 
rstrip()  The rstrip() function returns a copy of the string with the last characters removed from the end of the string (depending on the passed character argument). This means that the rstrip() function removes all the specified characters from the right side of the string. If no argument is passed, it removes blank spaces from the right side. read more 
strip()   The strip() function returns a copy of the string with the characters removed from the beginning and end of the string. (From the right and the left). Depending on the character argument being passed.  read more 
lstrip()   The lstrip() function returns a copy of the string with the leading characters removed (depending on the passed character argument). If no argument is passed, it removes the leading blank spaces from the left. read more 
expandtabs()   The expandtabs() function returns a new string with the "\t" tabs replaced with blank spaces. That is, the expandtabs() function specifies the amount of empty space to be replaced by the "\t" tabs in the string read more 
swapcase()  The swapcase() function converts all uppercase letters to lowercase and vice versa. That is, it converts text strings written in lowercase letters to uppercase letters. Text strings written in uppercase to lowercase letters read more 
join() The join() function is a Python built-in function used to join elements of a sequence. It returns a new string. It can be used with many data types List , Tuple , String , etc read more 
strip methods   The strip() function returns a copy of the string with the characters or whitespace removed from the beginning or end of the string. argument, the chars argument comes by default to remove whitespace. If the string contains no whitespaces and no chars argument is provided, the string is returned as is.. read more 



Tags


Python Python String string methods python string capitalize python python string upper method python string lower method python string swapcase method python string title method python string strip method python string join method python string center method python expandtabs method python string lstrip method python string strip python string rstrip method python string ljust method python string rjust method python string istitle method String handling functions in Python

Share page