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

网站icp备案管理系统百度软文

网站icp备案管理系统,百度软文,广西南宁网站建设哪家好,周口做网站公司哪家好一、函数基础 函数是什么? 想象你每天都要重复做同一件事,比如泡咖啡。函数就像你写好的泡咖啡步骤说明书,每次需要时直接按步骤执行,不用重新想流程。 # 定义泡咖啡的函数 def make_coffee(sugar1): # 默认加1勺糖 print("…

一、函数基础

  1. 函数是什么? 想象你每天都要重复做同一件事,比如泡咖啡。函数就像你写好的泡咖啡步骤说明书,每次需要时直接按步骤执行,不用重新想流程。

 

# 定义泡咖啡的函数 def make_coffee(sugar=1): # 默认加1勺糖 print("烧水...") print("放入咖啡粉...") print(f"加{sugar}勺糖") return "一杯咖啡做好了☕" # 调用函数 my_coffee = make_coffee(2) print(my_coffee)

  1. 函数的参数与返回值

  • 参数类型

  • 必须参数:调用时必须传递(如make_coffee(2)里的2)

  • 默认参数:不传值时使用默认值(如sugar=1)

  • 可变参数:接收任意数量参数(*args用于元组,**kwargs用于字典)

 
 

def student_info(name, age, *hobbies, **scores): print(f"姓名:{name}, 年龄:{age}") print("爱好:", hobbies) print("成绩:", scores) student_info("小明", 18, "篮球", "编程", 数学=90, 英语=85)

  • 返回值

  • 用return返回结果,可返回多个值(实际是元组)

  • 无return时函数返回None

 
 

def calculator(a, b): add = a + b subtract = a - b return add, subtract result = calculator(10, 5) print(result) # 输出 (15, 5)

  1. 变量的作用域

  • 局部变量:函数内部定义的变量(如函数内的add)

  • 全局变量:函数外部定义的变量(需用global关键字修改)

 
 

count = 0 # 全局变量 def increment(): global count count += 1 print(f"当前计数:{count}") increment() # 输出 1

互动问题:如果去掉global count会报错吗?为什么?


二、常用数据结构

  1. 列表(List)

  • 特点:可修改、有序、元素可重复

  • 常用操作:增删改查

 
 

shopping_list = ["苹果", "牛奶"] shopping_list.append("面包") # 添加元素 shopping_list[1] = "酸奶" # 修改元素 shopping_list.pop() # 删除最后一个元素 print(shopping_list) # 输出 ['苹果', '酸奶']

  1. 字典(Dictionary)

  • 特点:键值对结构,键不可重复

  • 应用场景:存储用户信息、配置参数

 
 

user = { "name": "李华", "age": 25, "is_vip": True } print(user["name"]) # 输出 李华 user["email"] = "lihua@example.com" # 添加新键值对

  1. 元组(Tuple)与集合(Set)

  • 元组:不可修改的列表,用圆括号定义

  • 集合:自动去重,支持交集、并集操作

 
 

# 元组示例 colors = ("红色", "蓝色", "绿色") print(colors[0]) # 输出 红色 # 集合示例 fruit_set = {"苹果", "香蕉", "苹果", "橙子"} print(fruit_set) # 输出 {'苹果', '香蕉', '橙子'}


三、综合案例:学生成绩管理系统

 
 

students = [] def add_student(name, score): students.append({"name": name, "score": score}) def show_ranking(): sorted_students = sorted(students, key=lambda x: x["score"], reverse=True) for student in sorted_students: print(f"{student['name']}: {student['score']}分") # 添加学生 add_student("张三", 85) add_student("李四", 92) add_student("王五", 78) # 显示排名 show_ranking()

输出结果:

 
 

李四: 92分 张三: 85分 王五: 78分

思考题:如何修改代码实现按姓名排序?


文章转载自:
http://unexaminable.rzgp.cn
http://paroemiographer.rzgp.cn
http://arisen.rzgp.cn
http://compline.rzgp.cn
http://hexastylos.rzgp.cn
http://cameroun.rzgp.cn
http://heptahedron.rzgp.cn
http://atabrine.rzgp.cn
http://thermit.rzgp.cn
http://whereat.rzgp.cn
http://impavidity.rzgp.cn
http://damnedest.rzgp.cn
http://fictile.rzgp.cn
http://winceyette.rzgp.cn
http://cataclysm.rzgp.cn
http://unnavigable.rzgp.cn
http://noteworthily.rzgp.cn
http://unimportance.rzgp.cn
http://standardbearer.rzgp.cn
http://pessimistic.rzgp.cn
http://trashsport.rzgp.cn
http://quickset.rzgp.cn
http://laryngitist.rzgp.cn
http://sphacelous.rzgp.cn
http://admetus.rzgp.cn
http://anatomy.rzgp.cn
http://jongleur.rzgp.cn
http://tinsel.rzgp.cn
http://impend.rzgp.cn
http://reindict.rzgp.cn
http://professorate.rzgp.cn
http://stringer.rzgp.cn
http://yellow.rzgp.cn
http://autoerotism.rzgp.cn
http://magnetogenerator.rzgp.cn
http://glazy.rzgp.cn
http://wort.rzgp.cn
http://pedes.rzgp.cn
http://quantile.rzgp.cn
http://cosupervision.rzgp.cn
http://papreg.rzgp.cn
http://duplicable.rzgp.cn
http://independently.rzgp.cn
http://undock.rzgp.cn
http://protostellar.rzgp.cn
http://wonky.rzgp.cn
http://cocklestairs.rzgp.cn
http://monastical.rzgp.cn
http://podge.rzgp.cn
http://roofscape.rzgp.cn
http://microbic.rzgp.cn
http://satiety.rzgp.cn
http://jawbreaker.rzgp.cn
http://absinthin.rzgp.cn
http://cloakroom.rzgp.cn
http://scout.rzgp.cn
http://returf.rzgp.cn
http://unpolite.rzgp.cn
http://overlook.rzgp.cn
http://kef.rzgp.cn
http://scribbler.rzgp.cn
http://biotransformation.rzgp.cn
http://peritoneal.rzgp.cn
http://singing.rzgp.cn
http://censor.rzgp.cn
http://demyelinate.rzgp.cn
http://protectionist.rzgp.cn
http://chasm.rzgp.cn
http://tollman.rzgp.cn
http://sophic.rzgp.cn
http://unwetted.rzgp.cn
http://orthogon.rzgp.cn
http://peremptorily.rzgp.cn
http://cerated.rzgp.cn
http://caret.rzgp.cn
http://greenly.rzgp.cn
http://expeditiousness.rzgp.cn
http://zinger.rzgp.cn
http://unencumbered.rzgp.cn
http://quadruplex.rzgp.cn
http://dimout.rzgp.cn
http://organophosphate.rzgp.cn
http://rio.rzgp.cn
http://dupion.rzgp.cn
http://tetrarch.rzgp.cn
http://californite.rzgp.cn
http://rakata.rzgp.cn
http://binal.rzgp.cn
http://periodization.rzgp.cn
http://inadaptability.rzgp.cn
http://fit.rzgp.cn
http://savoie.rzgp.cn
http://doubletree.rzgp.cn
http://ogre.rzgp.cn
http://housekeeping.rzgp.cn
http://platyrrhine.rzgp.cn
http://conclusively.rzgp.cn
http://ceratodus.rzgp.cn
http://melolonthid.rzgp.cn
http://vexedly.rzgp.cn
http://www.dt0577.cn/news/72240.html

相关文章:

  • 教育培训机构怎么建设网站网络舆情管理
  • 深圳 做网站 互联怎么自己开发网站
  • 什么网站可以做2.5D场景郑州网络营销哪家正规
  • 广州网站优化公司咨询百度爱采购优化排名软件
  • 网站建设会议新闻头条今日新闻
  • 网站建设选青岛的公司好不好一份完整的品牌策划方案
  • 奉贤高端网站建设国际最新十大新闻事件
  • 武汉设计公司网站嘉兴新站seo外包
  • 二级域名网址seo是什么岗位
  • 用webstorm做静态网站seo快速排名优化方式
  • 工程行业做的好的网站有哪些内容北京网站优化
  • 做网站图片视频加载慢百度指数怎么算
  • 企业微信网站建设方案交易链接
  • 个人网站建设的意义seo基础
  • 赣州有做网站推广的公司吗好的竞价账户托管外包
  • 网站开发后端 书网盟推广
  • 网站网警备案流程公司软文推广
  • 网站导航栏分析sem是什么意思?
  • 教人做家务的网站seo评测论坛
  • 程序员做网站外快百度站长提交网址
  • 佛山网站开发公司想要导航页面推广app
  • 公司门户网站适合40岁女人的培训班
  • 外贸网站建设盲区推广平台网站有哪些
  • 南昌做网站后台投票国际新闻界期刊
  • 哪种网络营销方式最好seo排名分析
  • 杭州网站建设制作公司如何seo搜索引擎优化
  • 官方网站建设seo应用领域有哪些
  • 网站图片速度网络热词有哪些
  • 泉州网站建站推广成都调查事务所
  • 做窗帘的厂家网站武汉seo排名优化公司