Youtube Live session on Tkinter

sum(iterable , start )
iterable :input iterable
start : Optional , number to be added to after getting the sum of elements.

Return the sum of the elements plus start if available.

Using list
print(sum(my_list)) # 8
Using tuple
print(sum(my_tuple)) # 8
Using start ( Optional )
print(sum(my_list,5)) # 16 

Data type of output

sum() returns same dtype of input number.
print(type(sum([4,6,1])))   # <class 'int'>
print(type(sum([1.4,6,1]))) # <class 'float'>

Difference between fsum() and sum()

fsum() is included in Python math module so we have to import it before using. Where as sum() is part of built in functions of core Python so no need to import any library.

fsum() returns always float dtype. However sum() returns the same dtype of input number.
math.fsum() Iterator any()

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer