Some of the string methods are covered in the set 3 below
String Methods Part- 1
More methods are discussed in this article
1. len() :- This function returns the length of the string.
2. count(“string”, beg, end) :- This function counts the occurrence of mentioned substring in whole string. This function takes 3 arguments, substring, beginning position( by default 0) and end position(by default string length).
The length of string is : 26 Number of appearance of geeks is : 2
3. center() :- This function is used to surround the string with a character repeated both sides of string multiple times. By default the character is a space. Takes 2 arguments, length of string and the character.
4. ljust() :- This function returns the original string shifted to left that has a character at its right. It left adjusts the string. By default the character is space. It also takes two arguments, length of string and the character.
5. rjust() :- This function returns the original string shifted to right that has a character at its left. It right adjusts the string. By default the character is space. It also takes two arguments, length of string and the character.
The string after centering with '-' is : ---geeksforgeeks---- The string after ljust is : geeksforgeeks------- The string after rjust is : -------geeksforgeeks
6. isalpha() :- This function returns true when all the characters in the string are alphabets else returns false.
7. isalnum() :- This function returns true when all the characters in the string are combination of numbers and/or alphabets else returns false.
8. isspace() :- This function returns true when all the characters in the string are spaces else returns false.
All characters are alphabets in str All characters are numbers in str1 All characters are not spaces in str1
9. join() :- This function is used to join a sequence of strings mentioned in its arguments with the string.
The string after joining is : geeks_for_geeks
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- List methods in Python
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
- Global and Local Variables in Python
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Regular Expressions in Python | Set 2 (Search, Match and Find All)
- Interesting facts about strings in Python | Set 2 (Slicing)
- String Formatting in Python using %
- Logical Operators on String in Python
- Python List Comprehension and Slicing
- Python | Set 4 (Dictionary, Keywords in Python)
- How to split a string in C/C++, Python and Java?
- Interesting facts about strings in Python | Set 1
- Python | Set 3 (Strings, Lists, Tuples, Iterations)
- Python | Set 2 (Variables, Expressions, Conditions and Functions)