Common string-related function summary in python, python string
This example summarizes the commonly used string-related functions in python. Share it with you for your reference. The specific analysis is as follows:
The following python code can be used to check strings, including whether they are all numbers, numbers, title words, uppercase letters, lowercase letters, and spaces, whether to start and end with a specified character.
My_string = "Hello World" my_string.isalnum () # Check if all characters are digits my_string.isalpha () # Check if all characters in the string are letters my_string.isdigit () # Check if the string contains digits my_string.istitle () # Check whether the string contains the title word my_string.isupper () # Check whether the string contains the capital letter my_string.islower () # Check whether the string contains the lowercase letter my_string.isspace () # Check whether the string contains spaces my_string.endswith ('D') # Check whether the string ends with the character d my_string.startswith ('H') # Check whether the string starts with an uppercase letter H
The returned results are shown below.
My_string = "Hello World" print every () # Falseprint my_string.isalpha () # Falseprint every () # Trueprint every () # Falseprint my_string.isspace () # Falseprint my_string.endswith ('D') # Trueprint my_string.startswith ('H') # True
I hope this article will help you with Python programming.