search()和match(),用起来更灵活
import re
str = "Welcome to my world. I have 12 apples."
if re.search(r"world", str).group() != "" :
print("match! ")
str = "abcABC"
if re.match(r"[a-zA-Z]+", str):
print("match! ", re.search(r"[A-Z]+", str).group())
else:
print("ummatch! ")
python中什么是序列,列表,元组,字符串,索引,区别是什么?序列:可通过偏移量来进行切片的对象。列表、元组、字符串都属于序列。
散列:无法通过偏移量来进行切片的对象。比如 *** 、字典
序列包括:列表、元组、字符串
列表:是最常用的数组,可以进行嵌套;
元组:相当于Enum,一旦创建,元组的值是不允许修改的;
字符串:顾名思义就是中英文字符以及标点符号等。
索引:序列中的每个元素被分配一个序号。注意索引默认从0开始。
python中列表,元组,字符串如何互相转换python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示:>>>s = "xxxxx"
>>>list(s)
['x', 'x', 'x', 'x', 'x']
>>>tuple(s)
('x', 'x', 'x', 'x', 'x')
>>>tuple(list(s))
('x', 'x', 'x', 'x', 'x')
>>>list(tuple(s))
['x', 'x', 'x', 'x', 'x'] 列表和元组转换为字符串则必须依靠join函数
1. str转list
list = list(str)
2. list转str
str= ''.join(list)
3. tuple list相互转换
tuple=tuple(list)
list=list(tuple)
python中字符串方法isnumeric和isdigit的区别是什么isdigit()
True: Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
False: 汉字数字
Error: 无
isnumeric()
True: Unicode数字,全角数字(双字节),罗马数字,汉字数字
False: 无
Error: byte数字(单字节)