fstring 和 海象赋值

都是python3.8的特性

fstring

def sum(a,b):
    return a +b

a = 1
print(f'{a = }, {sum(a, 2) = }')
print(f'a = {a}, sum = {sum(a, 2)  }')

a = 1, sum(a, 2) = 3
a = 1, sum = 3


海象 assignment expressions :=

a = [0] * 11
print(f'{a=}')

if (x:=len(a))>10:
    print(f"list is too long {x=}, expected <=10")

list is too long x=11, expected <=10


re 正则,group(0)打出来所有字符串,group(1)打印第一个括号匹配内容

m1 =re.search(r'(\d+)% off', ads)
print(f'{m1=}') 
print(f'{m1.group(0)}')
print(f'{m1.group(1)}')

m1=<re.Match object; span=(4, 11), match='20% off'>
20% off
20

posted @ 2020-08-15 15:46  vivi~  阅读(147)  评论(0编辑  收藏  举报