Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BasicFunctions.py
#python 3.5.2 #Functions in Python #1)Simplest function def add(x,y): return x+y print(add(10,20)) #2)In python a function can return multiple values at at time def add_sub(x,y): return x+y,x-y#these multiple values contitute a tuple print(add_sub(10,20)) #3)different ways of passing args to function def person_details(name,age): print('name: ',name) print('age: ',age) person_details('Satish',31)#Positioned args person_details(age=23,name='Ramesh')#Keyworded args def person_details(name,age=18):#default args print('name: ',name) print('age: ',age) person_details('Satish')#default args will be accessed person_details('Navin',45)#customized args will be accessed #4)Var-args functions: def sum(*num):#variable args are stored in a tuple(here num) sum=0 for e in num: sum=sum+e print('Sum = ',sum) sum(1,2,3,4,5,6,7,8,9,10) #biggest number from a list of numbers: def biggest_number(*list): big=list[0] for e in list: if big<e: big=e print('Max = ',big) biggest_number(1,3,2,4,0,2,90,56,67,-90) #keyworded var-args functions def employee_details(eid,**data): print('Eid ',eid) #print(data) for key,value in data.items(): print(key,value) employee_details(101,name='Satish',age=23,cont=234567) employee_details(102,name='Jatin',age=33,cont=237567,addr='S2 steet') employee_details(103,name='Ratish',age=43,cont=294567,addr='D1 street',blood_gp='O+')
run
|
edit
|
history
|
help
0
static
StringManipulation
Sum of two numbers
Sieve of Eratosthenes
estadale
Assignment-3c
PyTypeSub
PyClassLinSearch
PyBatScoreSOLID
iya