Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BasicFunctionsPrograms,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)
run
|
edit
|
history
|
help
0
me
total_tips
List problem - add items
24jan py
chickens,cows,pigs values defined
display age
HW. Bubble Sort Descending Order
Convert String to Lower Case
sen
Merge sort implementation