So far we saw a function which had no arguments, now we will learn about functions with arguments. A function can contain any number of arguments depending on the business requirement. Let's try to understand with an example:
def func(passArgument):
print passArgument
str = "hello all"
func(str)
In the preceding example, the func function accepts one argument which has a data type string. We create a variable str with a certain string statement assigned and then we call the func function and thereby pass the value of str. Finally, the output will look something like this:
In the preceding example, what will happen if we do not pass any argument to the function?
def func(passArgument):
print passArgument
str = "hello all"
func()
It will simply throw a TypeError as shown in the following screenshot:
Hence, it becomes mandatory to pass an argument to the function during function calling after the function has been defined to accept arguments.