03 2021 档案
摘要:文件处理 1,打开文件 open('文件名',encoding='utf8') 此处看文档在电脑是用什么编码存储的,如果是gbk,那么此处encoding = 'gbk;若是utf8,那么encoding = 'utf8' 例如: 打开文档:新闻 f = open('新闻',encoding= 'u
阅读全文
摘要:1,面向过程 过程:没有返回值的函数就是过程 一个步骤一个步骤来 例如:想实现 y = 2*x+1 def cal (x) : res = 2*x res = res + 1 return res 2,函数式 函数式 = 编程语言定义的函数 + 数学意义的函数 通俗来讲,函数式就是用编程语言去实现数
阅读全文
摘要:匿名函数 -基本语法结构: lambda x : x+1 x:形参 x+1 返回值 例如:以下函数相当于lambda x : x+1 def calc (x): return x +1 res = calc(10) print(res) 将函数用匿名函数表示 def change_name(): r
阅读全文
摘要:作用域 注意:函数,模块,类都有自己的作用域 for循环,while循环,if,else 都没有自己的作用域 def test1(): print("in the test1")def test(): print("in the test") return test1 》test1 是函数test1
阅读全文