Site icon Machine Learning Projects

Python Program to Return Multiple Values From a Function – 2023

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Return Multiple Values From a Function.

Example 1: Return values using a comma

# Python Program to Return Multiple Values From a Function

def name():
    return "Abhishek","Sharma"

# print the tuple with the returned values
print(name())

# get the individual items
name_1, name_2 = name()
print(name_1, name_2)

Output

('Abhishek', 'Sharma')
Abhishek Sharma

Example 2: Using a dictionary

def name():
    n1 = "Abhishek"
    n2 = "Sharma"

    return {1:n1, 2:n2}

names = name()
print(names)

Output

{1: 'Abhishek', 2: 'Sharma'}

Check out our other python programming examples

Exit mobile version