1、join 连接
s1 = 'dabai'
# 单引号里面得冒号是连接符,想以什么连接,引号里面就写什么
s2 = ':'.join(s1)
print(s2)
输出结果如下:
l1 = ['大白', '最帅', '最萌']
print(l1, type(l1))
# 将l1用(空字符)连接
l2 = ''.join(l1)
print(l2, type(l2))
l3 = '-'.join(l1)
print(l3)
2、isalnum(字符串由字母或数字组成) isalpha(字符串只由字母组成) isdecimal(字符串只由十进制组成)
isalnum
s1 = 'dabai123'
s2 = '123456'
s3 = '100①'
s4 = 'dabai*#'
s5 = 'dabai'
index = [s1, s2, s3, s4, s5]
# 字符串由字母或数字组成,s4结果应该为False
for i in (index):
print(i.isalnum())
输出结果如下:
isalpha
s1 = 'dabai123'
s2 = '123456'
s3 = '100①'
s4 = 'dabai*#'
s5 = 'dabai'
index = [s1, s2, s3, s4, s5]
# 字符串只由字母组成,s5结果应该为True
for i in (index):
print(i.isalpha())
输出结果如下:
isdecimal
s1 = 'dabai123'
s2 = '123456'
s3 = '100①'
s4 = 'dabai*#'
s5 = 'dabai'
index = [s1, s2, s3, s4, s5]
# 字符串只由十进制组成,s2结果应该为True,s3为False原因是①非十进制数字
for i in (index):
print(i.isdecimal())
输出结果如下:
常用的大概就这些了!!!