It is commonly used in python to detect string correlation function aggregation
- 2020-05-10 18:21:53
- OfStack
This example summarizes the common string correlation functions in python. Share with you for your reference. The specific analysis is as follows:
The python code below can be used to detect strings, including whether they are all Numbers, whether they contain Numbers, whether they contain title words, whether they contain uppercase letters, whether they contain lowercase letters, whether they contain Spaces, and whether they begin and end with the specified characters.
my_string = "Hello World"
my_string.isalnum() # Detects whether all characters are Numbers
my_string.isalpha() # Detects whether all characters in a string are letters
my_string.isdigit() # Detects whether a string contains a number
my_string.istitle() # Detects whether the string contains the title word
my_string.isupper() # Detects whether a string contains uppercase letters
my_string.islower() # Detects whether a string contains lowercase letters
my_string.isspace() # Detects whether the string contains Spaces
my_string.endswith('d') # Detects whether a string is a character d The end of the
my_string.startswith('H') # Detects whether a string is in uppercase H At the beginning
The return result is shown below
my_string="Hello World"
print my_string.isalnum() #False
print my_string.isalpha() #False
print my_string.isdigit() #False
print my_string.istitle() #True
print my_string.isupper() #False
print my_string.islower() #False
print my_string.isspace() #False
print my_string.endswith('d') #True
print my_string.startswith('H') #True
I hope this article is helpful for you to design Python program.