函数解析——python学习第三次总结

孤街浪徒 提交于 2019-11-29 09:55:48

.str字符串类型(二)

1.  isalpha  判断目标字符串中是否只含字母

  表达式  str.isalpha()  ==>  bool

  示例:

1 a = 'alex'
2 v = a.isalpha()
3 print(v)# 输出# True

  源码:

1     def isalpha(self, *args, **kwargs): # real signature unknown
2         """
3         Return True if the string is an alphabetic string, False otherwise.
4         
5         A string is alphabetic if all characters in the string are alphabetic and there
6         is at least one character in the string.
7         """
源码

 

2.  isdecimal

     isdigit  都是用来判断目标字符串是否是数字,下面这个不光能判断纯文本,还能判断复杂符号。

  表达式  str.isdecimal()  ==>  bool

               str.isdigit()  ==>  bool

  示例:

1 a = '②'
2 b = a.isdecimal()
3 c = a.isdigit()
4 print(b,c)# 输出# false true

  源码:

1     def isdecimal(self, *args, **kwargs): # real signature unknown
2         """
3         Return True if the string is a decimal string, False otherwise.
4         
5         A string is a decimal string if all characters in the string are decimal and
6         there is at least one character in the string.
7         """
isdecimal
1     def isdigit(self, *args, **kwargs): # real signature unknown
2         """
3         Return True if the string is a digit string, False otherwise.
4         
5         A string is a digit string if all characters in the string are digits and there
6         is at least one character in the string.
7         """
isdigit

 

3.  

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!