def display_message():#定义一个函数名称以冒号结束
print("函数的定义,已经行参和实参")#函数要执行的代码块
display_message()#调用这个函数
'''8-2'''
def favorit_work(title):#定义一个函数名称以冒号结束,括号内是一个形参,可以定义多个形参
print("one of my FAVORITE book is "+ title + "in wonderland")
favorit_work('python ')#调用函数并以位置的形式使用实参
'''8-3'''
def mak_shirt(size,info):#定义一个函数名称以冒号结束,括号内是一个形参,可以定义多个形参
print("shirt size is : " + str(size))
print("info is :" + info )
mak_shirt(size=55,info='my love is .NET ')#调用函数并以关键字的形式使用实参
'''8-4'''
def mak_shirt(size,info='I Love Python !'):#定义一个函数名称以冒号结束,括号内是一个形参,可以定义多个形参,并给形参给定一个默认值info='I Love Python !'
print("\n shirt size is : " + str(size))
print("\tinfo is :" + info )
mak_shirt('L')
mak_shirt('M')
mak_shirt('S','I Love C# ')
def descrite_ctiy(city_name,countries='china'):
print("\n" + city_name + " is in " + countries.upper())
descrite_ctiy('SC')
descrite_ctiy(city_name='CQ')
descrite_ctiy(city_name='Paris',countries='French')
'''8-5'''
def descrite_ctiy(city_name,countries='china'):
print("\n" + city_name + " is in " + countries.upper())
descrite_ctiy('SC')
descrite_ctiy(city_name='CQ')
descrite_ctiy(city_name='Paris',countries='French')
def city_country(city_name,coubtrues):
print_city = city_name + "," + coubtrues
return print_city
a = city_country('cq','china')
def make_album(s_name,jj_name,numbers=''):
if numbers:
album = {'姓名': s_name, '专辑名': jj_name,'歌曲数':numbers}
else:
album = {'姓名': s_name, '专辑名': jj_name}
return album
albums = make_album('刘德华','冰雨')
print(albums)
albums = make_album('张杰','离站')
print(albums)
albums = make_album('许巍','大海',3)
print(albums)
"""
'''8-8'''
def make_album(s_name, jj_name, numbers=''):#定义一个函数3个形参吗其中最后一个为可选参数
#判断是否有带可选参数写进字典
if numbers:
album = {'姓名': s_name, '专辑名': jj_name, '歌曲数': numbers}
else:
album = {'姓名': s_name, '专辑名': jj_name}
return album
ac = True#定义个个标志
while ac == True:
user = input("姓名")
jj_m = input("专辑名")
sl = input("歌曲数。如果不填直接按回车")
if sl == False :#判断用户歌曲数是否有填写
info = make_album(user,jj_m)
else:
info = make_album(user,jj_m,sl)
jx = input("是否继续 Y/N")
if jx == 'n':
ac = False
print(info)
'''8-9'''
def show_magicians(name):
for i in name:
print(i)
names = ['a','asdasd','asdasssda','qwesada']
show_magicians(names)
print("\n")
'''8-10'''
def show_magicians(namem):
for i in namem :
mes = ' the Great'
print(mes + i)
names = ['a','asdasd','asdasssda','qwesada']
nm=[]
show_magicians(names)
'''8-11'''
def make_great(name,nename):
while name:
i = name.pop()#把列表的值删除并赋值给变量i
nename.append(i)#用列表append的方法把刚刚取到的i 写进列表
print("\n")
make_great(names[:],nm)#以切面的形式形成副本,作为函数的实参。
print(names)
print(nm)