Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Keyword and Positional Argument in Python
Next article icon

Parameters are variables defined in a function declaration. This act as placeholders for the values (arguments) that will be passed to the function.

Arguments are the actual values that you pass to the function when you call it. These values replace the parameters defined in the function.

Although these terms are often used interchangeably, they have distinct roles within a function. This article focuses to clarify them and help us to use Parameters and Arguments effectively.

Parameters

A parameter is the variable defined within the parentheses when we declare a function. 

Example:

Python
# Here a,b are the parametersdefsum(a,b):print(a+b)sum(1,2)

Output
3

Arguments

An argument is a value that is passed to a function when it is called. It might be a variable, value or object passed to a function or method as input.

Example:

Python
defsum(a,b):print(a+b)# Here the values 1,2 are argumentssum(1,2)

Output
3

Types of arguments in python

Python functions can contain two types of arguments:

  • Positional Arguments
  • Keyword Arguments

Positional Arguments

Positional Arguments are needed to be included in proper order i.e the first argument is always listed first when the function is called, second argument needs to be called second and so on.

Example:

Python
deffun(s1,s2):print(s1+s2)fun("Geeks","forGeeks")

Output
GeeksforGeeks

Note: The order of arguments must match the order of parameters in the function definition.

Variable-Length Positional Arguments

To handle multiple arguments within the function, you can use *args.

Python
deffun(*args):# Concatenate all argumentsresult="".join(args)print(result)# Function callsfun("Geeks","forGeeks")# Two arguments


To read in detail, refer -*args and **kwargs in Python

Keyword Arguments

Keyword Arguments is an argument passed to a function or method which is preceded by a keyword and equal to sign (=). The order of keyword argument with respect to another keyword argument does not matter because the values are being explicitly assigned.

Python
deffun(s1,s2):print(s1+s2)# Here we are explicitly assigning the valuesfun(s1="Geeks",s2="forGeeks")

Output
GeeksforGeeks

Parameter Passing in Python
Visit Courseexplore course icon
Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp