在python中实现对list求和及求积

yipeiwu_com5年前Python基础

如下所示:

# the basic way
s = 0
for x in range(10):
 s += x

# the right way
s = sum(range(10))


# the basic way
s = 1
for x in range(1, 10):
 s *= x

# the other way
from operator import mul
reduce(mul, range(1, 10))

以上这篇在python中实现对list求和及求积就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Pytorch 实现数据集自定义读取

以读取VOC2012语义分割数据集为例,具体见代码注释: VocDataset.py from PIL import Image import torch import torch....

Python实现遍历目录的方法【测试可用】

Python实现遍历目录的方法【测试可用】

本文实例讲述了Python实现遍历目录的方法。分享给大家供大家参考,具体如下: # *-* coding=gb2312 *-* import os.path import shuti...

使用PyInstaller将python转成可执行文件exe笔记

1、安装PyInstaller PyInstaller的作用如标题所说,首先需要下载PyInstaller和UPX,UPX是用来压缩exe的,点击超链接下载吧,目前稳定版本是1.3,注意...

Pandas:Series和DataFrame删除指定轴上数据的方法

如下所示: import numpy as np import pandas as pd from pandas import Series,DataFrame 一、drop方法:...

python支付宝支付示例详解

python支付宝支付示例详解

本文实例为大家分享了python支付宝支付示例代码,供大家参考,具体内容如下 项目演示: 1、输入金额 2、扫码支付: 3、支付完成: 一、注册账号 https://openho...