Skip to main content

19.Python Arguments

Python Arguments 
    Information can be passed into functions as arguments.The values passed in the parameters () of a function are called arguments. It is possible to add as many arguments as needed, by indicating the separation with a comma. It is very important to match the number of arguments with the function definition while calling the function. Otherwise, it will result in error.Note that A parameter is the variable listed inside the parentheses in the function definition whereas an argument is the value that is sent to the function when it is called. 

Syntax: 
Def function_name(parameters):# function definition 
    Body/statements 
Function_name(arguments)#function calling 
Program
def power(x):# x is the parameter 
    return x**9 
def add(x): 
    return x+5 
a=power(2)#2 is the argument 
print(a) 
b=power(5) 
print(b) 
c=add(89) 
print(c) 
Output 
512 
1953125 
94 
Default Arguments: 
    It is also possible to provide default values in the function definition. If we call the function without argument, it uses the default value 
Program 
def mul(x=14,y=4):#x=14,y=4 is default 
    return x*y 
multiply=mul(24,5) 
print("with both arguments(24*5)",multiply) 
multiply=mul(24,) 
print("with one argument(24*4)",multiply) 
multiply=mul() 
print("without arguments/Default argument(14*4)",multiply) 
Output 
with both arguments(24*5) 120 
with one argument(24*4) 96 
without arguments/Default argument(14*4) 56 
Keyword Arguments: 
    In order to assign the values to the arguments according to their position.Python allows functions to be called using keyword arguments. When we call functions using keyword arguments, the order of the parameters can be changed. 
Program
def calc(x,y,z): 
    return x*y+z 
calculation=calc(10,49,25) #here x=10,y=49,z=25 
print("normal argument passing:",calculation) 
calculation=calc(z=10,x=49,y=25)# here a key is assigned 
print("Calculation using key=value:",calculation) 
Output
normal argument passing: 515 
Calculation using key=value: 1235 
Watch the video below to learn python in detail!

Happy Learning!!
















Comments

Popular posts from this blog

Get Ethical Hacking Project #1

Thanks for your interest in our course This is a paid course, 150 rs for Indian people, 5$ for international people Instructions to get course: Indian people can get the course by paying using this UPI id   tamilhacks@ybl  (KARTHIKEYAN T) send 150 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)     The above mentioned method is most preferable. if you don't have a upi id app, install  phonepe  or  google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100 Rs for tax and other charges here )   After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that . the course is in zip format, so after downloading the file extra

Learn c++ in Tamil | Complete guide and tutorial | Beginner to Advance all concepts explained.

hi guys welcome , all the coding used in video are available here : /* hi guys welcome to learn c++ in tamil what is C++ how what software your own program schools,clg,institute.... start 1.interest 2.patience 3.fun 4.practise computer program - app - programming source code - hardware - fb running , executing machine language :  101010 assembly lang : mov h1; high lang : c , c++....java , js , python  eg :  a+b .....1001010  compiler :  human to machine              machine to human  rules :  a+b;  usage:  games, manufacturing , embedded , finance , graphics , etc...  Guide: 1.problem 2.solution - alternative 3.program  - C++ 4.compile  - turboc , ide , codeblocks , cmd 5.result   - library file - linker : #include<iostream.h>    input , output std::cout<<"welcome";   standard character out << " "; primary section : 1.statements   ;  end 2.functions   main() 3.syntax  , syntax error pra

Get Bug Bounty Course

Thanks for your interest in our course Limited Offer This is a paid course, Rs 10000 ,Rs 1000  for Indian people, 75$ 15$ for international people , 50$ 10$ for Srilankan people Instructions to get course: Indian people can get the course by paying using this UPI id  tamilhacks@ybl  send 1000 Rs to this upi id with subject bug bounty and after payment take a screenshot and send that to email id tamilhackstech@gmail.com - you will get the course within 24 hours. (there will be no tax, when paying using upi id)    The above mentioned method is most preferable. if you don't have a upi id app, install phonepe or google pay   app and register there and pay easily  or  pay here using the alternate method to get this course, this link cost 18% gst for the course . (nearly 30-100Rs for tax and other charges here ) After payment you will receive a payment confirmation mail along with a downlink for the course, you can download the course file using that. As for international peopl