Built-in-Methods of String Datatype Part — I

Shubham Hanmant Pawar
3 min readSep 29, 2023

--

Python is a great language. It is relatively easy to learn and has an intuitive syntax. The rich selection of libraries also contributes to the popularity and success of Python.

However, it is not just about the third-party libraries. Base Python also provides numerous methods and functions to expedite and ease the typical tasks in data science.

In this article, we will go over built-in string methods in Python. You might already be familiar with some of them but we will also see some of the rare ones.

The methods are quite self-explanatory so I will focus more on the examples to demonstrate how to use them rather than explaining what they do.

1. Capitalize

It makes the first letter uppercase.

2 . Casefold

Converts all the uppercase letters in a string to lowercase letters.

3. Center

Center align a string and pad both the ends by a space or another specified character.

4. Count

Returns the number of occurrences of a substring in the given string.

5. Endswith

Returns True if the string ends with the specified value, otherwise False.

6. Expandtabs

The expandtabs() method sets the tab size to the specified number of whitespaces.

7. Find

The find() method returns the index of the first occurrence of the substring (if found). If not found, it returns -1.

8. Index

The method returns the index of a substring inside the string (if found). If the substring is not found, it raises an error.

9. Isalnum

Returns True if all the characters are alphanumeric.

10. Isalpha

Check if all the characters in a string are alphabetic characters.

11. Isdecimal

Returns a Boolean value TRUE if the input string contains all decimal characters; otherwise, it returns FALSE.

12. Isdigit

Returns True if all the characters are digits, otherwise False.

13. Islower

Returns True if all the characters are in lowercase, otherwise False.

Further Built-in-function we will in the next Article.

#vevcodelab.

http://vevcodelab.com/

--

--

No responses yet