python初学入门之 函数

欢迎大家加入京东淘宝捡垃圾群:698433653
可以自己试着跑,初学入门 函数的使用!

# #打印问候语
# def greet_user(username):
#     """显示简单的问候语"""
#     print("hello!")
#     print("hello!"+username.title()+"!")#向参数传递信息
# greet_user('jesse')

# #传递实参
# def describe_pet(pet_name, animal_type='dog'):
# #def describe_pet(pet_name, animal_type):#亦可
#     '''显示动物的信息'''
#     print("\nI have a"+animal_type+".")
#     print("My "+animal_type+"'s name is "+pet_name.title()+'.')
# # 等效的函数调用
# describe_pet('harry')
# describe_pet(animal_type='dog',pet_name='harry')#关键字实参
# describe_pet(animal_type='dog',pet_name='harry')#关键字实参

#返回值
# def describe_pet(pet_name, animal_type):
#     '''返回整洁的值'''
#     full_name = pet_name+' '+animal_type
#     return full_name.title()#首字母大写
#
# mu = describe_pet('aaa','bbb')
# print(mu)
#让实参变成可选的
# def describe_pet(pet_name, animal_type,middle=''):
#     '''返回整洁的值'''
#     if middle:
#
#         full_name = pet_name+' '+middle+' '+animal_type
#     else:
#         full_name = pet_name + ' ' + animal_type
#     return full_name.title()  # 首字母大写
#
# mu = describe_pet('aaa','bbb','ccc')
# print(mu)
# mu = describe_pet('ddd','eee')
# print(mu)

# #返回字典
# def bulid_person(f_name,l_name):
#     person={'f':f_name,'l':l_name}
#     return person
# mu = bulid_person('jj','kk')
# print(mu)

#传递列表
# def greet_user(names):
#     '''向列表中的每位用户都发出简单的问候'''
#     for name in names:#for循环 依次输出列表的数据
#         msg = "Hello,"+name.title()+"!"
#         print(msg)
# usernames = ['h','t','m']
# greet_user(usernames)
#在函数中修改列表
# un = ['a','b','c']
# co = []
# while un:
#     cu =un.pop()
#     print("Print model:"+cu)
#     co.append(cu)
# print("\nThe following models have been printed:")
# for cos in co:
#     print(cos)
#传递 任意 数量的实参
# def make_pizze(*top):
#     print(top)
# make_pizze('pp')
# make_pizze('aa','bb','cc')
def make_pizze(*top):
    for topp in top:
        print(topp)
make_pizze('a','s','d')
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值