day19__第三次作业

一、break 与 continue 的区别

答:break 是结束全部循环,continue 是结束当前循环,开始进行下一循环

 

二、函数传递参数时,所用的内存地址一样吗?

答:一样

name = '123'
def func():
    print(id(name))
func()             # 12322384
print(id(name))    # 12322384

 

三、lambda 省内存, 因为它即用即消失

 

四、统计字符串中大写字母,小写字母和数字的个数,并以字典为列表返回给调用函数

 

五、可变长参数:*args, **kwargs

def func(x,z,y=5):
    print(x,y,z)
func(1,2,3)     # 1 3 2

def func(x,y,*z):
    print(x,y,z)
func(1,2,3,4,5,6)     # 1 2 (3,4,5,6)

def func(x,*z,**y):
    print(x,y,z)
func(1,2,3)     # 1 {} (2,3)

def func(x,*y,**z):
    print(x,y,z)
func(1,name=2,age=3)     # 1 () {'age':3, 'name':2}

def func(x=2,*y,**z):
    print(x,y,z)
func(name=2,age=3)     # 2 () {'age': 3, 'name': 2}
def func(*y,**z):
    print(y,z)
func([1,2,3,4])    # ([1, 2, 3, 4],) {}

def func(*y,**z):
    print(y,z)
func(*[1,2,3,4])    # (1, 2, 3, 4) {}

def func(*y,**z):
    print(y,z)
func(*[1,2,3,4],name = 'alex',age = 12)    # (1, 2, 3, 4) {'name': 'alex', 'age': 12}

def func(*y,**z):
    print(y,z)
func(*[1,2,3,4],{'name':'alex','age':12})    # (1, 2, 3, 4, {'name': 'alex', 'age': 12}) {}

 

六、python3 和 python2.7 中 range 的 区别

Python3 中,不会生成值,只有用的时候才会生成,Python2.7 直接生成一个列表,值已经生成

 

七、取出 l1,l2,l3 的第一个元素,并用下划线相连

l1 = ['alex',12,34]
l2 = ['is',32,45]
l3 = ['boy',22,33]
print('_'.join(list(zip(l1,l2,l3))[0]))   # alex_is_boy

 

八、

name = '12345'
def func():
   name = "seven"
   def outer():
       name = "eric"
       def inner():
           global name
           name = "蒙逼了吧..."
       print(name)
   print(name)

ret = func()      # seven
print(ret)        # None
print(name)       # 12345


namelist = ['alex']
def func():
    namelist = []
    namelist.append('at')
func()
print(namelist)     # ['alex']

namelist = ['alex']
def func():
    namelist.append('at')
func()
print(namelist)     # ['alex', 'at']

 

posted @ 2018-10-24 10:36  *精灵鼠*  阅读(106)  评论(0编辑  收藏  举报