SlideShare a Scribd company logo
1 of 11
def f(a):
print(a)
f(a=5)
5
def f(a):
print(a)
f()
Traceback (most recent call last):
File "C:/Users/smcse/AppData/Local/Programs/Python/Python36-
32/fn.py", line 3, in <module>
f()
TypeError: f() missing 1 required positional argument: 'a'
Required Arguments
def f(a):
print(a)
f(a,b)
Traceback (most recent call last):
File "C:/Users/smcse/AppData/Local/Programs/Python/Python36-
32/fn.py", line 3, in <module>
f(a,b)
NameError: name 'a' is not defined
def f(c,d):
print(a)
print(b)
f(a=5,b=10)
def f(a,b):
print(a)
print(b)
f(a=5,b=10)
5
10
Keyword Arguments
Traceback (most recent call last):
File "C:/Users/smcse/AppData/Local/Programs/Python/Python36-
32/fn.py", line 4, in <module>
f(a=5,b=10)
TypeError: f() got an unexpected keyword argument 'a'
def f(b,a):
print(a)
print(b)
f(a=5,b="hi")
5
hi
#!/usr/bin/python
# Function definition is here
def printinfo( name, age ):
"This prints a passed info into this function"
print("Name: ", name)
print("Age ", age)
return;
# Now you can call printinfo function
printinfo( age=50, name="miki" )
printinfo( name="miki" )
Name: miki
Age 50
Traceback (most recent call last):
File "C:/Users/smcse/AppData/Local/Programs/Python/Python36-32/funn.py", line
12, in <module>
printinfo( name="miki" )
TypeError: printinfo() missing 1 required positional argument: 'age'
def f(a,b=9):
print(a)
print(b)
f(a=5,b=10)
def f(a,b=9):
print(a)
print(b)
f(a=5)
5
9
Default Arguments
def f(a,b=9):
print(a)
print(b)
f(a=5,b)
5
10
def add(b,*a):
z=0
z=z+b
for i in a:
z=z+i
return z
>>> import funn
>>> funn.add(1)
1
>>> funn.add(1,2)
3
>>> funn.add(1,34,67)
102
>>> funn.add()
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
fn.add()
TypeError: add() missing 1 required positional argument: 'b'

More Related Content

Similar to Arguments in Functions.pptx

List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidora
Jinyuan Loh
 
Functions in python
Functions in pythonFunctions in python
Functions in python
Ilian Iliev
 

Similar to Arguments in Functions.pptx (20)

Funkcija, objekt, python
Funkcija, objekt, pythonFunkcija, objekt, python
Funkcija, objekt, python
 
Terminal linux commands_ Fedora based
Terminal  linux commands_ Fedora basedTerminal  linux commands_ Fedora based
Terminal linux commands_ Fedora based
 
Functional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with PythonFunctional Programming inside OOP? It’s possible with Python
Functional Programming inside OOP? It’s possible with Python
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdf
 
List command linux fidora
List command linux fidoraList command linux fidora
List command linux fidora
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180
 
PHP 5.3
PHP 5.3PHP 5.3
PHP 5.3
 
Py3k
Py3kPy3k
Py3k
 
Examples -partII
Examples -partIIExamples -partII
Examples -partII
 
7.0 files and c input
7.0 files and c input7.0 files and c input
7.0 files and c input
 
Built in function
Built in functionBuilt in function
Built in function
 
Unit5
Unit5Unit5
Unit5
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
File Handling in C
File Handling in CFile Handling in C
File Handling in C
 
The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.7 book - Part 29 of 196The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.7 book - Part 29 of 196
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 

Recently uploaded

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 

Recently uploaded (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Arguments in Functions.pptx

  • 1.
  • 2.
  • 3. def f(a): print(a) f(a=5) 5 def f(a): print(a) f() Traceback (most recent call last): File "C:/Users/smcse/AppData/Local/Programs/Python/Python36- 32/fn.py", line 3, in <module> f() TypeError: f() missing 1 required positional argument: 'a' Required Arguments def f(a): print(a) f(a,b) Traceback (most recent call last): File "C:/Users/smcse/AppData/Local/Programs/Python/Python36- 32/fn.py", line 3, in <module> f(a,b) NameError: name 'a' is not defined
  • 4.
  • 5.
  • 6. def f(c,d): print(a) print(b) f(a=5,b=10) def f(a,b): print(a) print(b) f(a=5,b=10) 5 10 Keyword Arguments Traceback (most recent call last): File "C:/Users/smcse/AppData/Local/Programs/Python/Python36- 32/fn.py", line 4, in <module> f(a=5,b=10) TypeError: f() got an unexpected keyword argument 'a' def f(b,a): print(a) print(b) f(a=5,b="hi") 5 hi
  • 7.
  • 8. #!/usr/bin/python # Function definition is here def printinfo( name, age ): "This prints a passed info into this function" print("Name: ", name) print("Age ", age) return; # Now you can call printinfo function printinfo( age=50, name="miki" ) printinfo( name="miki" ) Name: miki Age 50 Traceback (most recent call last): File "C:/Users/smcse/AppData/Local/Programs/Python/Python36-32/funn.py", line 12, in <module> printinfo( name="miki" ) TypeError: printinfo() missing 1 required positional argument: 'age'
  • 10.
  • 11. def add(b,*a): z=0 z=z+b for i in a: z=z+i return z >>> import funn >>> funn.add(1) 1 >>> funn.add(1,2) 3 >>> funn.add(1,34,67) 102 >>> funn.add() Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> fn.add() TypeError: add() missing 1 required positional argument: 'b'