零基础自学python复习基础 函数 (五)

家电维修 2023-07-16 19:17www.caominkang.com家电维修技术

前言

目录

一、函数

                1.使用 def 创建函数
                2.调用函数
                3.默认参数
                4.传参 list()
                5.传参dict()
                6.传参tuple()
                7.传参set()
                8.return()返回值
                9.关键字参数
                10.任意参数
                11.递归
                12.让实参变成可的
                13.结合使用函数和hile循环
                14.结合使用位置实参和任意数量实参


前言python函数基础进行复习 一、函数

                1.使用 def 创建函数

def Kg():
 print("李白 唐代  ")


                2.调用函数

def li_bai():
 print("李白")


                3.默认参数

li_bai()
def k_python(李白  = "李白"):
 print("李白 "+李白 )
k_python("王维")
k_python("杜甫")
k_python()
k_python("传参")


                4.传参 list()

def k_u(kjys):
 for x in kjys:
  print(x)
kjys  = ["调用函数","传参","def"]
k_u(kjys)


                5.传参dict()

def k_u(kjys):
 for d in kjys:
  print(d)
kjys = dict(name = "铠甲勇士",id = "123456")
print(kjys)


                6.传参tuple()

def e_d(kjys):
 for  in kjys:
  print()
kjys = tuple(("说出新时代","字符串","数字","字典"))
e_d(kjys)


                7.传参set()

def _a(kjys):
 for a in kjys:
  print(a)
kjys = set(("tuple","list","set","dict"))
_a(kjys)
_a("李白")


                8.return()返回值

def k_p(x):
 return 4  x
print(k_p(1))
print(k_p(4))
def T_t(d):
 return "铠甲勇士"  == d
print(T_t("李白"))
print(T_t("铠甲勇士"))


                9.关键字参数

#key = value 语法发送参数 参数的顺序无关紧要
def R_t (kjys1,kjys2,kjys3):
 print("刑天铠甲后传" + kjys1)
R_t(kjys1= "关键字参数",kjys2 = "key = value",kjys3="顺序")


                10.任意参数

#如果您不知道将传递给您的函数多少个参数,请在函数定义的参数名称前添加 。
#如果参数数目未知,请在参数名称前添加 
def n_(kjys):
 print("任意参数")
n_("铠甲勇士","李白","python")


                11.递归

def k_k(n):
 if (n>0):
  g = str(n) + str(k_k(n-1))
  print(g)
 else:
  g = 0
  return g
 print("蜡笔")
k_k(4)


                12.让实参变成可的

def g(q,,r):
  = q++r
 return 
d = g("铠甲勇士t","地虎t","items")
print(d)
d = g("龙虎门t","和平精英t","王者荣耀")
print(d)


                13.结合使用函数和hile循环

def h(k,n):
 d =k
 return d
hile True:
 print("t铠甲勇士")
 print("bai")
 e= input("输入你的密码")
 if e == "bai":
  break
  = h(e)
 print()


                14.结合使用位置实参和任意数量实参

def g(d,y):
 print("实参"+str(d))
 for y in y:
  print(y)
g(4,"放弃不难")
g(4,"但坚持一定很酷")

Copyright © 2016-2025 www.jianfeikang.com 建飞家电维修 版权所有 Power by