摘要:
如何搜索字符串中包含区号和分机号的第一个出现的电话号,并提取电话号中的区号、电话号和分机号。要求如下: 1.区号固定是3位数字 2.电话号至少是7位数字 3. 分机号至少是3位数字 4. 区号、电话号和分机号之间用连字符分割 import re # 正则表达式分组 m = re.search('\d
阅读全文
posted @ 2022-04-20 11:19
yuminhu
阅读(708)
推荐(0)
摘要:
1. 描述match和search的区别 match用于匹配 search用于搜索 import re m1 = re.match('.*python', 'I love python') print(m1) m2 = re.search('python', 'I love python') pri
阅读全文
posted @ 2022-04-20 11:06
yuminhu
阅读(96)
推荐(0)
摘要:
1. match函数的作用 import re print(re.match('hello', 'hello')) print(re.match('.*hello', 'hello')) print(re.match('hello', 'ahello')) <re.Match object; spa
阅读全文
posted @ 2022-04-20 10:44
yuminhu
阅读(162)
推荐(0)
摘要:
1. 如何将列表中的元素(字符串类型的值)连接在一起(首尾相接) a = ['a', 'b', 'c', 'd', 'e'] s = '' print(s.join(a)) s = '+' print(s.join(a)) abcdea+b+c+d+e 2. 字符串的join方法的作用是什么,使用j
阅读全文
posted @ 2022-04-19 21:18
yuminhu
阅读(45)
推荐(0)
摘要:
1. 如果让字符串居中显示,有哪些方法 center方法 format方法 2. 请使用center方法让字符串居中显示,两侧显示#号 print('<'+'hello'.center(30) + '>') print('<'+'hello'.center(30, '#') + '>') print
阅读全文
posted @ 2022-04-19 21:09
yuminhu
阅读(58)
推荐(0)
摘要:
1. 字符串的format方法有几种指定参数方式 1. 默认方式(传入的参数与{}一一对应) 2. 命名参数 3. 位置参数 2. 通过代码详细描述 s1 = 'Today is {}, the temperature is {} degrees.' print(s1.format('Saturda
阅读全文
posted @ 2022-04-19 21:02
yuminhu
阅读(170)
推荐(0)
摘要:
# 通过索引 s1 = 'hello world' print(s1[0]) print(s1[2]) # 分片 print(s1[6:9]) print(s1[6:]) print(s1[::2]) print(s1[::-1]) # 乘法 s2 = 'xyz' print(10 * s2) pr
阅读全文
posted @ 2022-04-19 20:36
yuminhu
阅读(26)
推荐(0)
摘要:
1. 在python语言种哪些格式化方式可以直接使用变量 fstring方式 2.请用代码描述如何使用fstring格式化字符串 name = 'Bill' age = 20 def getAge(): return 21 s = f"我是{name}, 我今年{age}岁, 明年{getAge()
阅读全文
posted @ 2022-04-19 20:03
yuminhu
阅读(126)
推荐(0)
摘要:
1. 在python语言中有多少种格式化字符串的方法? 1. %格式化 2. 模板字符串 3. 字符串的format方法 4. fstring 2. 请解释什么是模板字符串,如何使用? 通过Template对象封装 $放置一些占位符,并通过substitute方法用实际的值替换这些占位符 from
阅读全文
posted @ 2022-04-19 19:40
yuminhu
阅读(32)
推荐(0)
摘要:
d = {'a': 123, 'b': '456', 'c': 'xyz'} print(d) print(type(d)) import json json_str = json.dumps(d) print(json_str) print(type(json_str)) d1 = json.lo
阅读全文
posted @ 2022-04-19 19:24
yuminhu
阅读(65)
推荐(0)