Function with *args

EasyFunction Programs · 18 of 39

Write a Python function that accepts any number of numbers with *args and prints their cubes.

Advertisement
Input
5, 6, 8, 7
Output
tuple (5, 6, 8, 7)
125 216 512 343

Approach

  1. *args collects the values into a tuple.

Solution

Python
def cubes(*args):    print(type(args).__name__, args)    print(*(n ** 3 for n in args)) cubes(5, 6, 8, 7)
Output
tuple (5, 6, 8, 7)
125 216 512 343
Advertisement

Learn the concept

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

More function programs

← All 39 Function Programs