Skip to Main Content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.

Python for Basic Data Analysis: 2.2 Functions - Arguments

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of 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. 

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:

Video Guides