2019-07-06:练习

#encoding=utf-8
"""
复习正则表达式的分组
"""
#1.groups分组数量
#2.groupindex获取表达式中所有分组的别名和分组序号组成的字典
import re
p=re.compile(r'(\w+)(\w+)(\d+)')
p1= re.compile(r'(\w+)(\w+)(?P.*)')
p2=re.compile(r'(?P.*)(\w+)(\w+)')
print(p.groups)
print(p1.groupindex)
print(p2.groupindex)

#3.递归倒序打印1-10
def downData(n):
    if 1<= n <=10:
        print(n)
        n-=1
        return downData(n)
    else:
        return n
#print(downData(10))

#4.递归升序打印1-10
def upData(n):
    if n<=10:
        print(n)
        n += 1
        return upData(n)
    else:
        return n
print(upData(1))

#5.使用递归的方式倒序打印这个列表[1,2,3,4,5,6]
reList=[]
def downList(n):
    if n>0:
        reList.append(n)
        n-=1
        return downList(n)
    else:
        return reList
print(downList(6))

#方法二
a = [1,2,3,4,5,6]
def prt_num(lst):
    if len(lst) >= 1:
        print(lst.pop())
        prt_num(lst)
print(prt_num(a))


 

你可能感兴趣的:(Python)