Back to Browse

Mastering String Handling Function in Python | 35 Function Must Know

62 views
Jan 28, 2023
14:36

Python provides a wide range of built-in string handling functions that allow for the manipulation and formatting of strings. Some of the most commonly used functions include str.capitalize(), which capitalizes the first letter of a string and makes the rest of the letters lowercase, str.count(sub), which returns the number of non-overlapping occurrences of a substring within a string, and str.find(sub), which returns the lowest index in a string where a substring is found. Another useful function is str.format(), which allows for the replacement of placeholders in a string with specified values. This function can be used with positional and keyword arguments, as well as with dictionaries and other mapping types. For example, 'My name is {} and I am {} years old'.format('John', 30) would return the string 'My name is John and I am 30 years old'. Python also provides functions for testing the properties of a string, such as str.isalnum(), which returns True if a string contains only alphanumeric characters, and str.isalpha(), which returns True if a string contains only alphabetic characters. Additionally, there are functions for testing the case of a string, such as str.islower() and str.isupper(). Another useful string handling function is str.join(iterable), which concatenates all elements of an iterable (such as a list or tuple) with the string as a separator. For example, ", ".join(["apple", "banana", "cherry"]) would return the string "apple, banana, cherry". Other common string handling functions include str.replace(old, new), which replaces all occurrences of a specified substring with a new substring, str.strip([chars]), which removes specified leading and trailing characters from a string, and str.split([sep]), which splits a string into a list of substrings using a specified separator. In summary, Python provides a variety of built-in string handling functions that allow for the manipulation, formatting, and testing of strings, making it a powerful tool for working with text data. Python Docs: https://docs.python.org/3/ ⌚Timestamps⌚ 0:00 Introduction 1:16 str.len() Method 1:35 str.upper() Method 2:02 str.lower() Method 2:09 str.replace(old, new) Method 2:37 str.split(separator) Method 3:15 str.find(substring) Method 3:58 str.join(iterable) Method 4:38 str.startswith(substring) Method 5:17 str.endswith(substring) Method 5:46 str.isalnum() Method 6:25 str.isalpha() Method 6:51 str.isdigit() Method 7:33 str.strip() Method 8:13 str.lstrip() Method 8:32 str.rstrip() Method 9:08 str.format() Method 10:00 str.capitalize() Method 10:26 str.center(width) Method 11:02 str.count(substring) Method 11:36 str.encode(encoding) Method 12:13 str.expandtabs(tabsize) Method 12:48 str.swapcase() Method 13:42 str.zfill(width) Method ❤️My Story❤️ I'm currently working as a Machine learning Engineer and Software developer in past 8 years. I'm working on various software products and various technologies. I overall manage over 10 teams and a lot of different projects in various locations. Thanks, Love you all, Cheers ❤️ ❤️Hashtags❤️ #python #pythonprogramming #pythontutorial #pythoncoding #pythoncode #pythontips #pythonhacks #pythonforbeginners #pythontutorials #stringfunctions

Download

0 formats

No download links available.

Mastering String Handling Function in Python | 35 Function Must Know | NatokHD