sum()

http://www.adilwaseem.com/

Introduction
The returns with the sum of number or iterable.

Syntax
sum(iterable[, start]) -> value

Parameters
iterable

Examples
The method returns the sum of list.
>>> x=[99,22,1,3,55,5,33,21,44]
>>> sum(x,0)
283

sum(int())
The method sum() the int() value.
 >>> x="2232"
>>> y=33232
>>> int(x)+y
35464
>>> x+y

sum(map())
The map() returns with sum of two tuples.
 interable1=(55,458,572,101)
interable2=(11,3,4,5,6,6)
sum_value=sum(map(lambda a,b: a+b, interable1, interable2))
print(sum_value)
>>> 
1209
>>>

sum(map())
The function returns with the sum of three tuple.
import math
x=(math.acos(1),math.asin(1),math.atan(1))
y=(math.sin(-1),math.cos(-1),math.tan(-1))
z=(math.cosh(.1),math.sinh(.1),math.tanh(.1))
print("The sum is", sum(map(lambda a,b,c: a+b+c, x,y,z)))
>>>
The sum is 1.7024569992982896
>>>

if statement sum(map(lamda))__lt__(value()
If statement returns that the sum of the x/y is not less than 2.
 import math
x={math.factorial(81),math.sqrt(49),math.pow(4,2),math.e,math.exp(44)}
y={math.floor(3.12),math.fmod(3,2),math.fabs(22), math.ceil(1)}
if sum(map(lambda a,b: a/b, x,y)).__lt__(2):
                                                        print("The sum of x and y is less than 2")
else:
       print("The sum of x and y is greater than 2.")
>>> 
The sum is greater than 2.
>>>


if statement sum(map(lambda).__le__()
The lambda returns with equation computation.
import math
x=[math.log(2,10),math.log10(22), math.log2(2)]
y=[math.trunc(2.1)]
if sum(map(lambda a,b: a+b/2, x,y)).__le__(y):
    print("The return is large or equal to 2.0")
else:
   print("The value does not meet the criteria")

>>> 
The return is large or equal to 2.0
>>>


sum[list]
The method returns with:
import operator
import random
d=operator.pos(b)
f=c+d
list=[1,19,33,31]
g=sum(list)
print(f/g)

>>>
(0.05995071123597758+0j)



Comments