
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What is the 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().
- Related Articles
- What is the difference between rest parameters and the arguments object in Javascript?
- What is the difference between default and rest parameters in JavaScript functions?
- What is the difference between pass by value and reference parameters in C#?
- Parameters & Arguments in JavaScript.
- What is the difference between = and == operators in Python?
- What is the Difference Between Scala and Python?
- What is the difference between the != and operators in Python?
- What is the difference between Core Python and Django Python?
- What is the difference between os.open and os.fdopen in python?
- What is the difference between attributes and properties in python?
- What is the difference between __str__ and __repr__ in Python?
- What is the difference between dict.items() and dict.iteritems() in Python?
- What is the difference between global and local variables in Python?
- What is the difference between root.destroy() and root.quit() in Tkinter(Python)?
- What is the difference between single and double quotes in python?
