sum()

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
my_list=[1,2,5]
print(sum(my_list)) # 8
Using tuple
my_tuple=(1,2,5)
print(sum(my_tuple)) # 8
Using start ( Optional )
my_list=[2,4,5]
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()


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







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 Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer