IDE 集成开发环境

python魔法方法

__init__
__str__
__new__
__del__
__call__
__repr__
__getattr__
def __getattr__(self, item):# item代表要获取的属性名
    pass

 python18天-pycharm & 正则表达式

题目:想要添加属性think.different.itcast

使用__getattr__函数,item就是属性,可以代入进去。返回值应为self

python18天-pycharm & 正则表达式

调试debug

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

正则表达式

英文Regular Expression 描述某种规则的表达式   正则表达式使⽤单个字符串来描述、 匹配
⼀系列匹配某个句法规则的字符串。 在很多⽂本编辑器⾥, 正则表达式通常
被⽤来检索、 替换那些匹配某个模式的⽂本。 

RE模块 校验,通过正则表达式对字符串进⾏匹配  匹配对象具有group方法,用来返回字符串的匹配部分

下表摘自python之RE模块的正则表达式学习

 python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

表示数量

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

 python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

例子:匹配0-100之间的数字

import re

re.match(r"\d{1,2}$|100$","200")

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

 r 原始字符串  

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

(?P<name>)中的字母P大写

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

贪婪模式

正则表达式模式中使⽤到通配字, 那它在从左到右的顺序求值时, 会尽量“抓
取”满⾜匹配最⻓字符串
解决⽅式: ⾮贪婪操作符“? ”, 这个操作符可以⽤在"*","+","?"的后⾯, 要求
正则匹配的越少越好。
python18天-pycharm & 正则表达式

python18天-pycharm & 正则表达式

 

相关文章:

  • 2021-12-19
  • 2022-01-07
  • 2021-11-24
  • 2022-12-23
  • 2021-11-03
  • 2021-11-22
  • 2021-10-29
  • 2021-07-01
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案