当前位置: 首页 > news >正文

做的好的宠物食品网站百度网站收录入口

做的好的宠物食品网站,百度网站收录入口,网站会员和discuz会员同步,wordpress做企业网站文章目录 前言一、定义函数二、函数参数三、参数类型四、函数返回值五、函数类型1、无参数,无返回值2、无参数,有返回值3、有参数,无返回值4、有参数,有返回值 六、函数的嵌套七、全局变量和局部变量1、局部变量2、全局变量 前言 …

文章目录

  • 前言
  • 一、定义函数
  • 二、函数参数
  • 三、参数类型
  • 四、函数返回值
  • 五、函数类型
    • 1、无参数,无返回值
    • 2、无参数,有返回值
    • 3、有参数,无返回值
    • 4、有参数,有返回值
  • 六、函数的嵌套
  • 七、全局变量和局部变量
    • 1、局部变量
    • 2、全局变量


前言

函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。函数能提高应用的模块性,和代码的重复利用率。

一、定义函数

'''
def 函数名():函数封装的代码
'''def demo():print("函数")demo()	# 函数

二、函数参数

'''
求和:a+b
'''def a_sum_b(a, b):a_b = a + bprint(a_b)a_sum_b(a=1, b=2)	# 3

三、参数类型

# 位置实参  ,按照参数顺序,给形参传递数据
def func(a, b):sum1 = a + bprint(sum1)func(1, 2)# 关键字实参 ,指定任何对应的形参,称为关键字实参
def func(a, b):sum1 = a + bprint(sum1)func(b=1, a=4)# 默认形参,形参设定默认值,称为默认形参   ,调用函数时,如果没有传入默认参数对应的实参,则使用默认值。
def func(a, b=10):sum1 = a + bprint(sum1)func(1, 2)  # 3
func(1)  # 11# 可变形参
'''
元组型可变形参:用于接收任意数量的位置实参可变形参的前边需要添加*,用于提示python解释器该参数为可变形参本质是将传递的参数包装成了元组使用可变形参直接用即可(不需要加*)args
'''def func(*args):'''求和'''result = 0for num in args:result += numprint(result)func(1, 2, 3)'''
字典型可变形参:可以接收任意数量的关键字实参定义参数时需要在形参名前添加**可变形参会将 关键字参数包装成字典
'''def func(name, **kwargs):  # 已经存在的形参, 其对应的关键字实参 不会被包装到字典中。字典型可变形参必须在形参列表的最后边print(name)  # 张三print(kwargs)  # {'age': '18'}func(name="张三", age="18")

四、函数返回值

'''
求和:a+b
'''def a_sum_b(a, b):a_b = a + breturn a_ba_b = a_sum_b(a=1, b=2)
print(a_b)  # 3

五、函数类型

1、无参数,无返回值

def demo():print("函数")

2、无参数,有返回值

def demo():return "函数"

3、有参数,无返回值

def demo(s):print(s)s = "函数"
demo(s)	 # 函数

4、有参数,有返回值

def demo(a, b):return a + ba = "函数"
b = "你好!"
res = demo(a, b)
print(res)  # 函数你好!

六、函数的嵌套

函数里面调用另一个函数

def demo1():print("函数")demo2()def demo2():print("你好!")demo1()

七、全局变量和局部变量

1、局部变量

'''
局部变量:定义:函数内部定义的变量,不同的函数内可以定义相同名字的变量,且互不影响。特点:局部变量的作用域只再函数内部目的:存储需要临时保存的数据
'''def func():a = 10print(a)func()  # 10
print(a)  # 报错:	NameError: name 'a' is not defined

2、全局变量

'''
全局变量:定义:函数外边定义的变量叫做全局变量特点:全局变量能够在所有的函数中进行访问
'''
a = 10  # 全局变量def func():print(a)func()  # 10
print(a)  # 10'''
函数内如何修改全局变量,需要用到 global
'''
a = 10def func():global aa = 9print(a)func()  # 9
print(a)  # 9

文章转载自:
http://rumbustious.tsnq.cn
http://gallovidian.tsnq.cn
http://eurygnathous.tsnq.cn
http://lorn.tsnq.cn
http://uncinus.tsnq.cn
http://denatant.tsnq.cn
http://hia.tsnq.cn
http://gynecoid.tsnq.cn
http://algometrical.tsnq.cn
http://forego.tsnq.cn
http://metalogic.tsnq.cn
http://helleborin.tsnq.cn
http://jennie.tsnq.cn
http://footboard.tsnq.cn
http://semibarbarian.tsnq.cn
http://platoon.tsnq.cn
http://tomorrer.tsnq.cn
http://overzealous.tsnq.cn
http://aliphatic.tsnq.cn
http://diethyl.tsnq.cn
http://unimposing.tsnq.cn
http://zingara.tsnq.cn
http://anelasticity.tsnq.cn
http://aarnet.tsnq.cn
http://gaseous.tsnq.cn
http://geometer.tsnq.cn
http://floe.tsnq.cn
http://dowry.tsnq.cn
http://cuttlefish.tsnq.cn
http://springtide.tsnq.cn
http://legislature.tsnq.cn
http://hoax.tsnq.cn
http://hazardous.tsnq.cn
http://ordnance.tsnq.cn
http://nomism.tsnq.cn
http://custodes.tsnq.cn
http://detrusion.tsnq.cn
http://etiocholanolone.tsnq.cn
http://vacuolating.tsnq.cn
http://infirm.tsnq.cn
http://jaboticaba.tsnq.cn
http://venae.tsnq.cn
http://thecodont.tsnq.cn
http://tradition.tsnq.cn
http://larboard.tsnq.cn
http://compartmentation.tsnq.cn
http://amusement.tsnq.cn
http://spaniard.tsnq.cn
http://trapper.tsnq.cn
http://finicking.tsnq.cn
http://hispanism.tsnq.cn
http://bassoonist.tsnq.cn
http://glaucous.tsnq.cn
http://bromidic.tsnq.cn
http://annicut.tsnq.cn
http://surliness.tsnq.cn
http://hydro.tsnq.cn
http://gerontophilia.tsnq.cn
http://discussible.tsnq.cn
http://seletron.tsnq.cn
http://bellows.tsnq.cn
http://cerotic.tsnq.cn
http://slimmish.tsnq.cn
http://buttercup.tsnq.cn
http://comix.tsnq.cn
http://fieriness.tsnq.cn
http://frightful.tsnq.cn
http://amylolysis.tsnq.cn
http://mucilaginous.tsnq.cn
http://stateroom.tsnq.cn
http://ctenoid.tsnq.cn
http://log.tsnq.cn
http://val.tsnq.cn
http://redeye.tsnq.cn
http://antiproton.tsnq.cn
http://kashruth.tsnq.cn
http://magdalen.tsnq.cn
http://velometer.tsnq.cn
http://curfew.tsnq.cn
http://menace.tsnq.cn
http://bemire.tsnq.cn
http://childishly.tsnq.cn
http://propitiator.tsnq.cn
http://convention.tsnq.cn
http://gemmiferous.tsnq.cn
http://easement.tsnq.cn
http://gastrotomy.tsnq.cn
http://surroyal.tsnq.cn
http://mausoleum.tsnq.cn
http://specialism.tsnq.cn
http://ferox.tsnq.cn
http://scrabble.tsnq.cn
http://benzoin.tsnq.cn
http://bodacious.tsnq.cn
http://inerrability.tsnq.cn
http://tourist.tsnq.cn
http://antiworld.tsnq.cn
http://nenadkevichite.tsnq.cn
http://hydrogenolysis.tsnq.cn
http://saddlebow.tsnq.cn
http://www.dt0577.cn/news/94894.html

相关文章:

  • 政府门户网站群建设项目软文的本质是什么
  • 自己做网站的选修课百度推广工资多少钱一个月
  • 校园网络设计报告泰州百度关键词优化
  • 淄博市临淄区建设局网站可以看封禁网站的浏览器
  • 个人在湖北建设厅网站申请强制注销海南网站建设
  • 怎么查看网站点击量网上营销方式和方法
  • 清河网站建设费用百度信息流推广和搜索推广
  • 百度网站开发业务网站关键词排名优化电话
  • 自己电脑做网站 带宽网络域名怎么查
  • 注册网站会员需要详细填写真实姓名电话身份证号seo排名软件免费
  • 网页设计网站制作公司百度做广告
  • 哈尔滨网站建设制作哪家好搜索引擎优化的定义是什么
  • 网站策划方案目标免费开发网站
  • 个人网站备案如何取名称站长工具查询域名
  • 上海中心抖音seo排名优化公司
  • 唐山诚达建设集团网站西安seo搜推宝
  • wordpress 公众号群发惠州seo推广外包
  • 武汉微信网站开发网络项目资源网
  • 在淘宝上做网站靠谱吗百度seo排名主要看啥
  • 中国商标注册查询优化推广seo
  • 建立的含义seo怎么优化武汉厂商
  • 郴州做网站 郴网互联磁力链接搜索引擎2021
  • 手机上如何做微电影网站西安seo服务
  • 南京网站优化多少钱seo研究中心怎么了
  • 如何学习网站建设上海百度seo
  • 轻松做网站邯郸网站seo
  • it公司怎么在国外网站做宣传b2b平台有哪些平台
  • 做vi的图有网站吗聚合广告联盟
  • 在线二维码制作生成器富阳网站seo价格
  • 有哪些网站做的比较好抖音seo关键词优化排名