Python Forum
Need help with 'return' in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with 'return' in python
#3
If you want an example and how it works here.
def add(num1, num2):
    return num1 + num2

number = add(1, 1)
print(number)
Output:
2
It return a value from a function as seen above. Another example
import random

def two_random_numbers(minimum, maximum):
    num1 = random.randint(minimum, maximum)
    num2 = random.randint(minimum, maximum)
    return num1, num2

num1, num2 = two_random_numbers(1, 5)
numbers = two_random_numbers(1, 5)
print(num1)
print(num2)
print(numbers)
Output:
3 2 (4, 2)
Hope this helps
Reply


Messages In This Thread
Need help with 'return' in python - by Leo12143 - Jul-09-2019, 10:49 PM
RE: Need help with 'return' in python - by Yoriz - Jul-09-2019, 11:04 PM
RE: Need help with 'return' in python - by SheeppOSU - Jul-10-2019, 02:35 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020