Python String Methods 2

Source: Internet
Author: User
Tags string methods python isdigit

1. Python isalnum () method #检测字符串是否由字母和数字组成

Returns True if the string has at least one character and all characters are letters or numbers, otherwise False>>>'Hello'. Isalnum () True>>>'hello123'. Isalnum () True>>>'hello_123'. Isalnum () False>>>'The is string'. Isalnum () False>>>'Hello World'. Isalnum () False
View Code2. Python isalpha () method #检测字符串是否只由字母组成
Returns True if the string has at least one character and all characters are letters, otherwise False ' hello123 ' . Isalpha () False ' Hello World ' . Isalpha () False ' HelloWorld ' . Isalpha () True
View Code3. Python isdigit () method #检测字符串是否只由数字组成
returns True if the string contains only numbers otherwise False ' 12345 ' . IsDigit () True ' 12345a ' . IsDigit () False
View Code4. Python islower () method #检测字符串是否由小写字母组成
Returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are lowercase, otherwise False ' 2hello ' . Islower () True ' _hello ' . Islower () True ' Hello ' . Islower () False ' _hello ' . Islower () False
View Code5. Python isnumeric () method #检测字符串是否只由数字组成. This method is only for Unicode objects
' u ' prefix >>> u'123456'. IsNumeric () True>>> u' 123a456 ' . IsNumeric () False>>> u'123_456'. IsNumeric () False 
View Code6. Python isspace () method #检测字符串是否只由空格组成
returns True if the string contains only spaces, otherwise False '    ' . Isspace () True '   ' # \ t True ' _    ' . Isspace () False '   1  '. Isspace () False
View Code7. The Python Istitle () method #检测字符串中所有的单词拼写首字母是否为大写, and the other letters are lowercase
Returns True if all the words in the string are spelled with the first letter uppercase, and the other letter is lowercase, otherwise False ' Hello World ' . Istitle () True ' Hello World ' . Istitle () False ' HEllo World ' . Istitle () False ' Hello World123 ' . Istitle () True
View Code8. Python isupper () method #检测字符串中所有的字母是否都为大写
returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are uppercase, otherwise False ' HELLO World ' . Isupper () True ' HELLO World ' . Isupper () False
View Code9. Python Join () method #用于将序列中的元素以指定的字符连接生成一个新的字符串
 >>> seq = ( " a  " ,  " b  " ,  " c  "  )  >>>  " Span style= "COLOR: #800000" >+   " .join (seq)   " a+b+c   " >>> "   hello   " .join (seq)   " a hellob helloc   " 
View CodeThe Python len () method #返回对象 (character, list, tuple, etc.) length or number of items
" Hello World ">>> len (str)11>>> l = [1,2,3,4,5,6]>>> len (l)6
View Code

Python String Methods 2

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.