
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Arguments and Parameters in Python
The concept of arguments and parameters are part of Functions in Python. Therefore, before moving further let us learn how to create a function and parameterised function.
A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
Create a Function
Example
Let us create a basic function ?
# Define a function def sample(): print("Inside a Function") # Function call sample()
Output
Inside a Function
Create a Parameterized Function
Here, we are creating a function with a parameter ?
# Creating a Parameterised Function def sample(str): print("Car = ", str) # Function calls sample("Tesla") sample("Audi") sample("BMW") sample("Toyota")
Output
('Car = ', 'Tesla') ('Car = ', 'Audi') ('Car = ', 'BMW') ('Car = ', 'Toyota')
Parameters
Parameters are defined by the names that appear in a function definition. Parameters define what kind of arguments a function can accept. Therefore, according to the above example of a Parameterized Function, the following is a parameter i.e. str ?
# Function Definition def sample(str):
Arguments
Arguments are the values actually passed to a function when calling it. . Therefore, according to the above example of a Parameterized Function, the following are the arguments i.e Tesla, Audi, BMW and Toyota ?
# Function calls sample("Tesla") sample("Audi") sample("BMW") sample("Toyota")
Example
Let's see an example ?
# Function Definition def sample(name, rank): print("Employee Name = ",name) print("Employee Rank = ",rank) # Function call sample(rank = 3,name = "Tim")
Output
Employee Name = Tim Employee Rank = 3
Above, the name and rank are parameters of the sample() function.
The 3 and Tim and arguments of the sample() function.
Let us see another example, wherein we have **kwargs as well as a parameter ?
def func(foo, bar=None, **kwargs): pass
Output
func(10, bar=20, extra=somevar)
Above, the foo, bar, and kwargs are parameters of the func().
the values 10, 20, and somevar are arguments of the func().