Common Mistakes
Week 6 - User Defined Functions
1. No Return
If you are not assigning a return() to the function you define, python automatically assumes the output as None. You might want to see it here.
2. Incorrect Number of Arguments
If you have a function that takes in a specific number of arguments and you call that function with fewer or more variables, then you will see the following error:
TypeError: function() takes 2 positional arguments but 3 were given
3. Calling function() Incorrectly
If you call your function() with a typo in its name, then you will see the following error.
NameError: name 'funciton' is not defined
4. Varying number of inputs
If you define a function that can handle as many inputs as you give, you need to make sure that your function can process that information.
5. Defining arguments as variables inside
This redefinition may delete your global variables or reset their values. However, this is done in the initiation of a class usually.
6. Understanding local and global variables
Local variables are the ones that are defined temporarily and are discarded when that environment is closed. This environment can be loops or functions.
If you define a variable inside a local environment, you cannot call or use that variable directly globally. However, you can define global variables inside the loops.