Function to add two numbers

EasyFunction Programs · 1 of 39

Write a Python function that adds two numbers and returns the result.

Advertisement
Input
12, 30
Output
42
3.0

Approach

  1. Define add(a, b) that returns a + b.

Solution

Python
def add(a, b):    return a + b print(add(12, 30))print(add(2.5, 0.5))
Output
42
3.0

Line by line

Line 1

a and b are parameters; their values come from the call.

Line 2

return hands the result back so the caller can use it.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs