Skip to Main Content

Python for Basic Data Analysis

Start your data science journey with Python. Learn practical Python programming skills for basic data manipulation and analysis.

Functions with arguments

Extra information can be passed into functions using Arguments. The terms Arguments and Parameters mean the same thing, which is information to be passed into a function.

These Arguments can be specified after the function name, inside the parenthesis.

Using arguments in functions

Let's try it with a function that will print the given argument. In this case, a name.

What we have here is a function called what_is_my_name(name) with 1 Argument name.
 

The print function in the what_is_my_name function prints out the string "My name is" together with the given argument, which is "John". 

A function is not limited to only 1 argument. You can have as many arguments as you wish.

For example, if your functions require the input of 3 sources of data, then it might be beneficial to include 3 arguments. 

Let us expand our previous function that prints the given name. The new function below will take in the name and nickname of a person and print it.
 

Arguments for a function can be of any data type (String, Integer, Float, List, Dictionary etc.) and it will be treated as the same data type inside the function.

For example, if our argument is a list, it will be treated as a list inside the function. 

Video Guides

Activity

  1. Function with 1 argument: Create a function to print your own name
  2. Function with multiple arguments: Write a function with two inputs, first name and last name, and print them out. 
  3. Passing lists as arguments: Write a function that will individually print out all elements inside this list:

    my_list = ["Car","Bus","Taxi"]

Question 1 - Function with 1 argument

Create a function to print your own name

Question 2 - Function with multiple arguments

Write a function with two inputs, first name and last name, and print them out. 

Question 3 - Passing lists as arguments

Write a function that will individually print out all elements inside this list: