本节讨论Python下函数型参的预设值问题. Python在设计函数时,可以给型参预设缺省值,当用户调用函数时可以不输入实参.如果用户不想使用缺省预设值则需要给型参一一赋值,可以给某些型参赋值或不按型参顺序用表达式给型参赋值,说起来有些绕,我们看看例子好了! #define function: area with two args def area(width = 10, height = 10): z = width * height print(z) #define fucntion: ma
图的存在,让数据变得形象化.无论多么复杂的东西,都是简单的组合. import matplotlib.pyplot as plt import numpy as np dict = {'A': 40, 'B': 70, 'C': 30, 'D': 85} for i, key in enumerate(dict):#Circulate both index and value(Here is key) plt.bar(i, dict[key], color='r', width=0.2) plt
v2.2 (2.x)以后,python支持不会溢出的 long 型. v3.0后,确切的讲, int 型(依赖运行环境C编译器中long型的精度)消失了,long型替代 int 型,成为新的.不依赖运行环境的.无精度限制的(只要内存装得下)int型. 举个例子: ================== >>> a = 2147483647 # 32位机上,v3.0 以前 python 的 int 型能容纳的最大正整数,等同于 sys.maxint. >>> b = 1 &