1.sys函数,自行百度;
2.copy函数,和Java中的copy一样,有浅拷贝深拷贝两种,自行百度;
3.偏函数 这个函数挺有意思的,python的骚操作,用不用都行;
from functools import partial
# 定义一个测试函数
def testPartialFunction(a, b, c=1):
return a + b + c;
# 使用偏函数,此时定义了testPartialFunction方法,已经给a赋值为100,b赋值为200
testPartial = partial(testPartialFunction,100, 200);
# 直接调用了testPartialFunction函数进行计算
print(testPartial());
# 给c赋值为2进行计算输出
print(testPartial(2));
4.内置数学计算模块 math 其他的自行百度,太多了;
print("阶乘计算:{}".format(factorial(10)));
print("累加计算:{}".format(fsum(range(100))));
print("乘方计算:{}".format(pow(10,2)));
print("对数计算:{}".format(log2(10)));
print("余数计算:{}".format(fmod(10,3)));
print("四舍五入:{}".format(round(1.5)));
print("随机数据:{}".format(randint(0,10)));
testList = [1,2,3,4,5,6,7,8,9,10];
print("随机抽取数据:{}".format(choices(testList)));
5.MapReduce进行大数据量的处理;
# python内置函数提供了filter(),map()这样的函数进行数据的过滤,这个和Java中的stream流的意思我感觉差不多
# 还额外提供了reduce()函数来进行数据的统计;
testList = [1,2,3,4,5,6,7,8,9,10];
# 使用lambda函数遍历testList 使用filter取出其中为偶数的数字,再使用list函数将结果转换为集合;
filter_result = list(filter(lambda item : item % 2 == 0 , testList));
print(filter_result);
# 使用lambda函数遍历filter_result 使用map取出数据并且乘以2,再使用list函数将结果转换为集合;
map_result = list(map(lambda item : item * 2 , filter_result));
print(map_result);
# 使用lambda函数遍历map_result 使用reduce函数将结果集统计;
reduce_result = reduce(lambda x,y:x+y,map_result);
print(reduce_result);
所有代码如下,本人代码出处和学习视频-csdn程序员学院-python实战编程-;
from functools import partial;
from random import *;
from math import *;
from functools import reduce;
# 定义一个测试函数
def testPartialFunction(a, b, c=1):
return a + b + c;
# 使用偏函数,此时定义了testPartialFunction方法,已经给a赋值为100,b赋值为200
testPartial = partial(testPartialFunction,100, 200);
# 直接调用了testPartialFunction函数进行计算
print(testPartial());
# 给c赋值为2进行计算输出
print(testPartial(2));
print("阶乘计算:{}".format(factorial(10)));
print("累加计算:{}".format(fsum(range(100))));
print("乘方计算:{}".format(pow(10,2)));
print("对数计算:{}".format(log2(10)));
print("余数计算:{}".format(fmod(10,3)));
print("四舍五入:{}".format(round(1.5)));
print("随机数据:{}".format(randint(0,10)));
testList = [1,2,3,4,5,6,7,8,9,10];
print("随机抽取数据:{}".format(choices(testList)));
# python内置函数提供了filter(),map()这样的函数进行数据的过滤,这个和Java中的stream流的意思我感觉差不多
# 还额外提供了reduce()函数来进行数据的统计;
testList = [1,2,3,4,5,6,7,8,9,10];
# 使用lambda函数遍历testList 使用filter取出其中为偶数的数字,再使用list函数将结果转换为集合;
filter_result = list(filter(lambda item : item % 2 == 0 , testList));
print(filter_result);
# 使用lambda函数遍历filter_result 使用map取出数据并且乘以2,再使用list函数将结果转换为集合;
map_result = list(map(lambda item : item * 2 , filter_result));
print(map_result);
# 使用lambda函数遍历map_result 使用reduce函数将结果集统计;
reduce_result = reduce(lambda x,y:x+y,map_result);
print(reduce_result);