preface

People like to make excuses for their mistakes. S = “3[a]2[BC]”, return “aaABCBC”. In the implementation process, you need to determine if a string is a number, and almost reflexively, you want to implement a list of strings from 0 to 9 yourself, and then determine if the characters are in it. The implementation is as follows:

Python’s built-in libraries already do this for you. The most deadly thing is that I have used this method before, but in the actual use, I did not use. I can say that this is careless, as well as the examination of the time, ask what number square is equal to 4, I only wrote a 2, and then therefore lost -2 that half points, but I know, this is actually the foundation is not solid embodiment. It is a way of thinking that obtains knowledge from direct experience. After all, the Python string judgment method is used less often in everyday development, so IT has been neglected by me. In order to avoid making similar mistakes in the future, take this opportunity to pick up the bad pen. Summarize this knowledge to prevent forgetting it later

1. The startswith | judge whether to begin with a string

Example:

2. The endswith | determine whether ends in a string

Example:

3. Isupper | determine whether there are at least a capital letter, and all the letters are capitalized

Example:

4. Islower | determine whether there is at least one lowercase letter, and all the letters are lowercase

Example:

5. Isdigit | determine whether all nonnegative integers

Example:

6. Isalpha | determine whether all letters

Example:

7. Isalnum | determine whether all nonnegative integers or letters (isdigit or isalpha)

Example:

8. Isspace | determine whether all Spaces (including tabs)

Example:

9. Istitle | determine whether led by letter (ignoring the alphabetic characters)

Example:

10. Isdecimal | determine whether all the Arabic numeral non-negative integer (only accept unicode form input)

Example:

11. Isnumeric | determine whether all nonnegative integers (only accept unicode form input)

Example:

This is the collection of character judgment functions in python2. Python3 has introduced three new character judgment functions to make character judgment more powerful

12. Isidentifier | determine whether keyword or effective markers for the inside of a python

Example:

13. Isprintable | determine whether can print (including the empty string)

Example:

14. Isascii () | determine whether as ASCII (American Standard Code for Information Interchange (American Standard Code for Information Interchange).

Wikipedia -ASCII

Example:

The resources

  • The Python Standard Library » String Methods
  • Python’s built-in strings handle variable collation
  • Python: isdigit() vs. isdecimal()
  • The differences between the STR functions isdigit, isdecimal, and isnumeric in Python
  • Python’s built-in string methods