0% found this document useful (0 votes)
16 views7 pages

Arguments and Parameters in Python

Uploaded by

agrawalruchi912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Arguments and Parameters in Python

Uploaded by

agrawalruchi912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Arguments and parameters in python

These values are called parameters or


Formal parameters or formal
argument. (values being received)

These values are called arguments or


actual parameters or actual arguments (values being passed)

Passing types of arguments

Arguments can be any


> literals : Ankit(3, 4)

>variables :Ankit(a, b)

> expressions: Ankit(a+b, b)


Passing Parameters
================
Python supports three types of formal arguments

1. Positional (required arguments)


2. Default
3. Keyword(or named)

1. Default Argument
Before moving to default just go throw these code.

-----------------------------------------------------------------------------------------------------------------------------
==============================================================================

=====================================================================================

======================================================

=================================================================================
A default argument is an argument
that assumes a default value if a
value is not provided during the
function call.
def greet(name="Anshika"):
print("Hello," name)

# Call without argument (uses default)


greet()

# Call with argument (overrides default)


greet("Ayush")

Output:

Hello, Anshika
Hello, Ayush
Rules
required parameters should be before default parameter
2. Keyword Arguments (Named Arguments)
With keyword arguments, you can pass arguments in any order by specifying the parameter name.

def student_details(name, age):


print("Name:”, name,” Age: “age)

# Call using keyword arguments


student_details(name="Payal", age=17)
student_details(age=18, name="Yashika")

Output:

Name: Payal, Age: 17


Name: Yashika, Age: 18
3. Positional Arguments
Positional arguments must be passed in the correct order as they are defined in the function.

def introduce(name, grade):


print(name, “ is in grade ”, grade)

# Call with positional arguments


introduce("Manshi", 12)
introduce("Ayush", 11)

Output:

Manshi is in grade 12.


Ayush is in grade 11.

You might also like