×

### Python sum() Function in Linux - Step by step guide ? The sum() function in Python is used to sum the numbers in a list. Summing a list of numeric values ​​is a useful and mandatory thing everywhere. So for a Python programmer, sum() is a useful tool. You can match lists and tuples together by using sum().

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Python fuction queries.

In this context, we shall look into how to use the sum() function of Python.

#### What is the sum() Function in Python ?

The sum() function prints out the sum of the values ​​of the list. Basically, the sum() function can be used to calculate the sum of all values in an iterable object. This method is useful when you need the total value of a list of items, which is common in a number of mathematical calculations.

#### Python sum() Function Syntax

The Python sum() function adds up all the numerical values in an iterable, such as a list, and returns the total of those values. sum() calculates the total of both floating-point numbers and integers.

For instance, you could use the sum() method to calculate the total price of the products a customer purchases at a store.

Here's the syntax for the Python sum() method:

`\$ sum(iterable_object, start_value)`

The function sum() takes in two parameters:

• The iterable object that you would like to calculate the total of (required) such as lists, tuples.
• An extra number that you want to add to the value you're calculating (optional) which you want to add to the result.

#### sum() Return Value

sum() returns the sum of start and items of the given iterable.

#### Examples of using sum() Function

1. Take a look at the below function:

`a = (1, 2, 3)x = sum(a)print(x)`

It's output will give:

`6`

2. The basic sum() function:

`a = (3, 4, 5)# Apply sum() functionx = sum(a)# Return resultprint("Sum =",x)`

It's Output will give:

`Sum = 12`

3. Increase results:

`a = (3, 4, 5)# Apply sum() functionx = sum(a)print(x)# Plus 10y = sum(a, 10)print(y)`

Output will give:

`1222`

#### Conclusion

This article covers how to use the sum() function in Python. In fact, the sum() function adds the items of an iterable and returns the sum. Also it calculates the total of all numerical values in an iterable. sum() works with both integers and floating-point numbers. The sum() function has an optional parameter to add a number to the total.

#### Search by typing a one letter Word Term Here

• #### Install VidCutter on Linux Mint 21 "Vanessa" - Step by step guide

• #### Install TeXworks on Ubuntu 22.10 (Kinetic Kudu) - Step by step process

• #### DU Command in Linux - More about it ?

• #### Create a Network Bridge on CentOS 8 - Step by step guide ?

• #### What is CHOWN Command in Linux ?

• #### Check Ports in Use on Ubuntu 22.04 (Jammy Jellyfish)

• #### Install ZSH on Ubuntu 22.04 (Jammy Jellyfish) - Step by step guide ?

• #### How to use Ansible Loops ?

• #### Ansible 'When' Conditionals - More about it ?

• #### AWK Features Explained with Examples

• #### Bash "If String Equals" Comparison - Complete guide ?

• #### 6 Best Text Editors for Linux

• #### Disable the Network Interface on Boot in CentOS 8 - Step by step guide ?

• #### DMIDECODE Command in Linux - How to use it ?

• #### Compare Numbers in a Bash Script - How to do it ?

• #### Linux LSOF Command - Explained with Examples

• #### LVEXTEND Command in Linux - Explained with Examples ?

• #### PASSWD Command in Linux - Explained with Examples

• #### Replace a String in a File Using Ansible

• #### Rsync Command Options - Explained with Examples

• #### Execute Remote Command with SSH

• #### Linux sed Command Options - Explained with examples ?

• #### How Tags in Ansible Playbook works running Ubuntu 22.04 (Jammy Jellyfish) ?

• #### TAR Command Options in Linux - Explained with Examples

• #### Ansible "Debug" Module - Explained with Examples with Ubuntu

• #### ulimit Linux Command - Explained with Examples

• #### Working with Variables in Ansible running Ubuntu 22.04 (Jammy Jellyfish)

• #### Fix Inactive UFW Status on Ubuntu 22.04 (Jammy Jellyfish)

• #### Run Background Process in Ubuntu 22.04 (Jammy Jellyfish) Linux system

• #### UFW Allow Port on Ubuntu 22.04 (Jammy Jellyfish)

• #### UFW Remove Rule in Ubuntu 22.04 (Jammy Jellyfish) Linux system

• #### Python Compare Strings - How it works ?

• #### Which Flavour of Ubuntu Should You Choose ?

• #### Install pageedit editor on Ubuntu 22.04 (Jammy Jellyfish) - Step by step guide ?

• #### Install Webfs Server on Jammy Jellyfish Ubuntu 22.04 system

• #### Install kakoune Editor on Ubuntu 22.04 (Jammy Jellyfish) - Step by step guide ?

• #### Install Luakit browser on Ubuntu 22.04 (Jammy Jellyfish) - Step by step guide ?

• #### Install Gnome Edit on Ubuntu Jammy Jellyfish ( 22.04 ) - Step by step guide ?

• #### Install Pluma on Debian 11.4 (Bullseye) System - Step by step guide ?

• 