首页 > 其他分享 >函数 global全局变量; 局部变量;缺省参数

函数 global全局变量; 局部变量;缺省参数

时间:2023-07-05 12:46:24浏览次数:40  
标签:global name -- gender age funcx 缺省 student 全局变量

# 函数 在函数里设置全局变量,会因为被赋值而修改
x=2
def funcx():
    global x #这个x 是全局变量  会因为函数里面被赋值而修改
    x=9
    print("this x is in the funcx:-->",x)
funcx()
print("--------------")
print("this x is in the funcx:-->",x)
'''
this x is in the funcx:--> 9
--------------
this x is in the funcx:--> 9
'''
# 函数 求大于【6】岁的男生的列表  女生的列表
def statmf(students,minage=3):
    malelist=[]
    femalelist=[]
    for student in students:
        if student['age']>minage:
            if student['gender']=='male':
               malelist.append(student['name'])
            elif student['gender']=='female':
               femalelist.append(student['name'])
    print(f'男生{" ".join(malelist)}')# 一个字符串的方法,它将列表中的所有元素连接成一个字符串
#验证
students=[{'age':18,'name':'fqs','gender':'male'},
          {'age':3,'name':'d','gender':'male'},
          {'age':19,'name':'f','gender':'male'},
          {'age':35,'name':'a','gender':'male'},]
statmf(students)

'''
this x is in the funcx:--> 9
--------------
this x is in the funcx:--> 9
'''

 

标签:global,name,--,gender,age,funcx,缺省,student,全局变量
From: https://www.cnblogs.com/haha1988/p/17528213.html

相关文章

  • python中globals()的用法
    python中globals()的用法 1.获取所有的全局变量,获取到的内容如下:{'__name__':'__main__','__doc__':None,'__package__':None,'__loader__':<_frozen_importlib_external.SourceFileLoaderobjectat0x7efc4bd1d960>,�......
  • autosys set global viriables
    http://www.unix.com/unix-advanced-expert-users/70182-autosys-variable.htmlHiAll,Ineedtoloadafilewhichhasadateinthename.Sortoflikethis:filename.20080619.datIcreatedanautosysvariablethathasthatdateasthevalue20080619whichnam......
  • VS2022 - 取消global using
    如何取消globalusing?最近下载最新版VS之后,会自动生成GlobalUsings.g.cs,每次都想删除掉,但是都不好用,查了官网,需要手动添加如下配置:<ImplicitUsings>disable</ImplicitUsings>在csproj文件,也就是双击项目名,可以打开<ProjectSdk="Microsoft.NET.Sdk.Web"><PropertyGroup>......
  • GlobalMapper教程(DSM转点云)
    1.GlobalMapper将dsm先转点云分类树木房屋后生成等高线:https://www.bilibili.com/video/BV1V5411Q7Fv/2.35_Globalmapper专业版GlobalMapper_从入门到入土教程_用GM分类Lidar点云提取...:https://www.bilibili.com/video/BV16u411r76M/3.GlobalMapper1—点云分类-提取地面点......
  • GlobalProtect配合privacyIDEA对接ldap做二步验证
    #Authorhttps://cnblogs.com/id404GlobalProtect的和privacyIDEA的安装部署及基础设置可参考前一篇博文https://www.cnblogs.com/id404/p/17484847.html PaloAlto设备在前一篇文章的基础不需要修改,本文重点在privacyIDEA的配置上 一、对接ldap   点击TestLDAP......
  • 11、默认路由(缺省路由)、浮动路由(主备路由)
    静态路由分析可看,管理员配置的路由条目比较多,当网络环境比较大时,路由条目就非常复杂,尤其是部署在企业出口的路由器,不可能明细化配置复杂的静态路由信息,一般在边界路由器配置默认路由,也是静态路由的一种方式。默认路由格式:【H3C】iproute-static0.0.0.00.0.0.0下一跳IP地址......
  • LEARNING TO SAMPLE WITH LOCAL AND GLOBAL CONTEXTS FROM EXPERIENCE REPLAY BUFFERS
    发表时间:2021(ICLR2021)文章要点:这篇文章想说,之前的experiencereplay的priority比如PER,都是单个transition独立设置的,并没有考虑transition之间的关系。这篇文章提出了一个叫NeuralExperienceReplaySampler(NERS)的learning-basedsamplingmethod。这个方法用强化的方式来......
  • MySQL的wait_timeout 参数 set global 设置不生效
    MySQL服务连接数突然暴增,登录服务查看大都是sleep进程,并且1分钟会启用一个新的连接,紧急处理方案是需要手动去释放连接数。登录服务器查看当前超时时间mysql>showvariableslike'%timeout%';+-----------------------------+----------+|Variable_name|Valu......
  • nodejs 伪全局变量模块
    使用这个文件可以实现不同文件中读写变量,适合当做共享变量文件名:globals.tsletglobals:any={myGlobal:{value:'canbeanytype:String,Array,Object,...'},aReadonlyGlobal:{value:'thisvalueisreadonly',protected:......
  • 全局过滤器------GlobalFilter
    前言SpringCloud的网关提供了31中过滤器,但这些过滤器作用都是固定的。如果我们希望拦截请求,做自己的业务逻辑就需要用到全局过滤器。全局过滤器作用全局过滤器的作用也是处理一切进入网关的请求和微服务响应,与GatewayFilter的作用一样。区别在于GatewayFilter通过配置定义,处理......