# #列表推导式 # l=[i*2 for i in range(1,10)] # print(l) # #字典推导式 # dic={ i: i*2 for i in range(1,10)} # print(dic) # #集合推导式 # s={i for i in [1,2,3]} # print(s) # # **什么是 FastAPI?** # 答:FastAPI 是 Python 的高性能 web 框架,用来写接口,自动生成接口文档,自带请求数据校验。 #**什么是接口?GET POST PUT DELETE 分别作用?** # 答:接口就是后端提供给前端调用的入口。 # - GET:查询数据 # - POST:新增数据 # - PUT:完整更新数据 # - DELETE:删除数据 # **400 Bad Request**:请求参数错误 # **404 Not Found**:找不到资源 # 422 Unprocessable Entity:数据校验失败 # 500 Internal Server Error:服务器内部报错,代码异常 # from fastapi import FastAPI # app = FastAPI() # @app.get("/hello") # def hello(): # return {"hello"} # # def hello(): # print("hello") ### ORM 查询(简单版) # 题目:根据名字查询班级 # class_obj = db.query(ClassModel).filter(ClassModel.class_name == name).first() def a(): x=10 def b(): print (x) return b from fastapi import FastAPI app = FastAPI() @app.post("/hello") def hello(): print("hello") hello()