

In today’s session, we will talk about “functions” in python. The video will explain the introduction of “functions”, why “functions” are needed, encapsulate code in a function, default arguments, the difference between “local and global variables” and “document strings”.
Topics that are covered in this Python Video:
0:16 Functions introduction
1:14 why functions are needed
3:38 encapsulate code in function
3:44 Define function
11:38 Name argument
12:11 Global vs Local Variables
13:56 Default variable
15:29 Document strings
Video without background music:
Visit to download answers on exercises.
Next Video:
Python Tutorial – 11. Dictionaries and Tuples:
Website:
Facebook:
Twitter:
Patreon:
source
pls also post the answers for every exercise, so that we can correct our mistakes and learn how easily we can write the code .
can you please help, I'm not able to get the output even after writing the same code. I'm facing the same issue with the different programs also. Please help.
the program is not giving the same output, it is not adding the elements of the list. Please explain
the same program is not showing the exact output as yours, please help
it's just saying process finished
hello dear Friend – great stuff – i like it very much. Can we dl the jupiter-notes example somewhere !?
Thanks a lot
Thankyou so much for all this knowledge… You made it so easy… God bless u…
do you know how to solve for ascending order?
A function called IsAscending() will take in three integers, num1, num2 and num3 as parameters. The function will return the Boolean value of True if the numbers are in ascending order. Otherwise, the function will return False.
>>> IsAscending(1, 5, 9)
True
>>>IsAscending(1, 9, 5)
False
New exercises: https://github.com/codebasics/py/blob/master/Basics/Hindi/8_functions/8_functions_exercise.md
Video without background music: https://youtu.be/fz_BCnhEQYQ
def area_of_triangle(base, height):
return 1 / 2 * base * height
def area_of(base, height, shape='triangle'):
if shape == 'triangle':
return 1 / 2 * base * height
elif shape == 'rectangle':
return base * height
else:
return -1
def print_patter(length):
pattern = '*' * length
for i in range(len(pattern)):
print(pattern[0:i + 1])
print("area_of_triangle(10,20)", area_of_triangle(10, 20))
print("area_of(10, 20, 'rectangle')", area_of(10, 20, 'rectangle'))
print("area_of(10, 20, 'triangle')", area_of(10, 20, 'triangle'))
print("area_of(10, 20, 'ameaba')", area_of(10, 20, 'ameaba'))
print("area_of(10, 20)", area_of(10, 20))
print_patter(3)
print_patter(4)
1)def calculate_area(b,h):
area=(b*h)/2
return area
a=int(input('enter the base of tri:'))
b=int(input('enter the height of tri:'))
print ('The area is :' ,calculate_area(a,b))
2)def calculate_area(b,h,s=None):
if s == 4:
return b*h
elif s == 3:
return (b*h)/2
else:
return (b*h)/2
a=int(input('enter the base/lenght:'))
b=int(input('enter the height/breadth:'))
n=input('enter the no of sides:')
print ('The area is :' ,calculate_area(a,b,n))
3)def print_pattern(arg,n):
for i in range(arg+1):
print (i*n)
a=int(input('enter the int:'))
b=str(input('enter the string:'))
print( print_pattern(a,b))
Very well explained. Simple learning
there must be a way to assign to global variable
Hi Your explanation is one of the simplest to understand, Great keep it up. I have few suggestions and reqeuests1. Voice of few videos are not audible, can you do something. 2.Pl do more videos on Natural Language Processing (NLP) 3. Pl post more videos on machine learning algorithms. 3. Pl post more videos on R language 4. Kindly also post more videos on Python advance topics such as tkiner, Django …etc. 5. Kindly post more videos on mongodb. Once again thanks for wonderful knowledgeable videos specially for Indian students. It is giving very much clarity. Can you suggest some good books or websites to explore python more ?
thankyou
Great explanation
I could not understand at the end why the outside Total value was 0 when inside (5+8)=13. what is the difference?
Thank you for an excellent video that was very interesting to watch and clearly presented.
If I could give thousands thumbs up , I Would do definitely!!!! I watched many many different videos about Functions but I didn't understand how it work, but this video explain everything
Define function make_doctor() that takes a parameter name
get user input for variable full_name
call the function using full_name as argument
print the return value
sir …plzz give me the solution for this….either in the comments or to my email nehaksvij153@gmail.com
Very well explained, Thank you
excellent, very clearly explained
This was extremely helpful. Thank you for posting this.
excellent!! Thank you!!
# Exercise 2 a modified version
def cal_area(b,h,shape):
if shape == "triangel":
area = 0.5*b*h
return area
elif shape=="rectangle":
area2 = b*h
return area2
else:
area3 = 0.5*b*h
return area3
values=cal_area(50,10,"rectangle")
print "The area of the rectangle is :",values
values2=cal_area(50,3,"triangle")
print "The area of the triangle is :",values2
values2=cal_area(3,3,"circle")
print "The area of the triangle is :",values2
Hello everyone if there is any better way to answer the question 2 in the exercise kindly share with pls. so far this is best way i can tackle the question. Thanks
or i in range(1,6):
for j in range(1,i+1):
print (j)
print
i wrote that in pycharm but the output is vertical pls can anyone help. its a pattern printing though. Thanks
hi brother ,
my code is not working as it just do not consider function,
please help.
def calculate_total(exp):
total = 0
for item in exp:
total =total + item
return total
tom_exp = [200,100,300]
joe_exp = [400,500,600]
tom_total=(tom_exp)
joe_total=(joe_exp)
print ("tom_total :",tom_total)
print ("joe_total :",joe_total)
o/p-
"C:Program Files (x86)Python36-32python.exe" C:/code/hellow/function.py
tom_total : [200, 100, 300]
joe_total : [400, 500, 600]
Process finished with exit code 0
thx bro finally i got how functions really work 🙂