Python---基础----数据类型的内置函数(主要介绍字符串、列表、元组、字典、集合的内置函数)
2019-05-24
----------------------------
# isalpha() 检测字符串是否是字母组成 返回布尔值
s = 'I 狗like dog'
s1 = 'I狗likedog'
print(s.isalpha())
print(s1.isalpha())
---------------------------
# isalnum() 检测字符串是否有字母加数字组成 返回布尔值
s = 'I 狗li414ke dog'
s1 = 'I狗likedog132132'
s2 = '3133'
print(s.isalnum())
print(s1.isalnum())
print(s2.isalnum())
----------------------------
# isdigit() 检测字符串是否由整数组成
# isdecimal()
# isnumeric()
s = '123'
print(s.isdigit())
print(s.isdecimal())
print(s.isnumeric())
print('='*20)
s = b'101100'
print(s.isdigit())
#print(s.isdecimal())
#print(s.isnumeric())
print('='*20)
s = '123.2'
print(s.isdigit())
print(s.isdecimal())
print(s.isnumeric())
-----------------------------
# split() 用指定字符切割字符串 返回由字符串组成的列表
s = '日照香炉生紫烟*疑是银河落九天*飞流直下三千尺'
list1 = s.split('*')
print(list1)
---------------------------------
# splitlines() 以换行切割字符串
s = '''日照香炉生紫烟\n疑是银河落九天\n飞流直下三千尺'''
print(s.splitlines())
------------------------------