Common string-related function summary in python, python string

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.