For example:
def them_so (a, b):
tong = a + b
return tong
so1 = 5
so2 = 6
so3 = int (input ("Enter a number:"))
so4 = int (input ("Enter some more:"))
print ("The first two numbers are:", them_so (so1, so2))
print ("The sum of the following two numbers is:", them_so (so3, so4))
In the above example, the int (), input (), and print () functions are built-in functions in Python. Here, we define the them_so () function, whose function is to add two numbers, sum the two numbers and return the result. The output of this program is as follows:
Enter a number: 8
Enter another number: 10
The first two numbers are: 11
The sum of the following two numbers is: 18
Naming functions by function or task will make it easier for the reader to understand, you should practice this when code.
Python Exercises: More than 100 Python exercises have solutions (sample code)
Next lesson: Python function parameter
Previous article: Built-in Python functions