Shen's Blog

May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never taking more than you give.

1.变量和数据类型 环境 使用Python 3。 变量和数据类型 数字及其运算 和c语言类似, = 是赋值运算符, / 是除法运算符, 比较特殊的是, ** 是次方运算

2.函数和库 函数 问题:1.求阶乘$\begin{aligned}n!\end{aligned}$ def fac(n): # 求阶乘 if n == 1: # 收敛条件 return 1 else: return n * fac(n

3.Numpy numpy的功能 引入Numpy的目的 为何不直接用list? 慢 缺少数学操作 heights = [1.73, 1.68, 1.71, 1.89, 1.79] # 5人的身高 weights = [65.4, 59.2, 63.6, 88.4, 68.7] # 5人的体重 bmis = weights / heights ** 2

4.图形绘制 图形可视化是非常强大的工具 Hans Rosling的例子 Matplot from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "last_expr" import matplotlib.pyplot as plt year = [1950, 1970, 1990, 2010] # 世界人口数据 pop = [2.519, 3.692, 5.263, 6.972] plt.plot(year, pop) # 折线图 plt.show() plt.scatter(year, pop)

Python基础 [[1.变量和数据类型]] [[2.函数和库]] [[3.Numpy]] [[4.图形绘制]]