Python第一阶段03
1.文件操作:
# 指明编码 f = open("sisi", encoding="utf-8") # 读 data = f.read() print(data) # 写 f.write("思思") print(data) # 一行行读 f.readline() # 文件关闭 f.close()
2.函数:
def func1(): print("in the func1...") return 0 def func2(): print("in the func2...") x = func1() y = func2() def fun3(x, y): print(x + y) return x+y print(fun3(1,2)) # 函数不返回值默认是None
3.局部变量和全局变量作用域:
4.递归:
def calc(n): print(n) if int(n/2) > 0: return calc(int(n/2)) print(n) calc(10)
5.高阶函数:
一个函数参数是函数