Python Tutorial – 10. Functions

///Python Tutorial – 10. Functions

Python Tutorial – 10. Functions

FavoriteLoadingAdd to favorites

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

By |2020-01-20T01:18:13+00:00January 20th, 2020|Python Video Tutorials|28 Comments

28 Comments

  1. Josh Chowdary January 20, 2020 at 1:18 am - Reply

    pls also post the answers for every exercise, so that we can correct our mistakes and learn how easily we can write the code .

  2. shubham navghare January 20, 2020 at 1:18 am - Reply

    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.

  3. shubham navghare January 20, 2020 at 1:18 am - Reply

    the program is not giving the same output, it is not adding the elements of the list. Please explain

  4. shubham navghare January 20, 2020 at 1:18 am - Reply

    the same program is not showing the exact output as yours, please help
    it's just saying process finished

  5. Martin Kaspar January 20, 2020 at 1:18 am - Reply

    hello dear Friend – great stuff – i like it very much. Can we dl the jupiter-notes example somewhere !?

  6. Hamed Gandomkar January 20, 2020 at 1:18 am - Reply

    Thanks a lot

  7. Sai Krishna January 20, 2020 at 1:18 am - Reply

    Thankyou so much for all this knowledge… You made it so easy… God bless u…

  8. Poptropica 2002 January 20, 2020 at 1:18 am - Reply

    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

  9. 04nikunj January 20, 2020 at 1:18 am - Reply

    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)

  10. pavithra TG January 20, 2020 at 1:18 am - Reply

    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))

  11. sandesh patil January 20, 2020 at 1:18 am - Reply

    Very well explained. Simple learning

  12. spicytuna08 January 20, 2020 at 1:18 am - Reply

    there must be a way to assign to global variable

  13. Parag Patankar January 20, 2020 at 1:18 am - Reply

    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 ?

  14. shabbir Hussain January 20, 2020 at 1:18 am - Reply

    thankyou

  15. Ronald Johnson January 20, 2020 at 1:18 am - Reply

    Great explanation

  16. Abhishek B January 20, 2020 at 1:18 am - Reply

    I could not understand at the end why the outside Total value was 0 when inside (5+8)=13. what is the difference?

  17. Francis Mannion January 20, 2020 at 1:18 am - Reply

    Thank you for an excellent video that was very interesting to watch and clearly presented.

  18. Shiva Mirdar January 20, 2020 at 1:18 am - Reply

    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

  19. neha samala January 20, 2020 at 1:18 am - Reply

    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

  20. Azizul Haque Khandaker January 20, 2020 at 1:18 am - Reply

    Very well explained, Thank you

  21. JSL LSJ January 20, 2020 at 1:18 am - Reply

    excellent, very clearly explained

  22. Dogs Are the Best January 20, 2020 at 1:18 am - Reply

    This was extremely helpful.  Thank you for posting this.

  23. Lisa Miller January 20, 2020 at 1:18 am - Reply

    excellent!! Thank you!!

  24. adigun Orlami January 20, 2020 at 1:18 am - Reply

    # 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

  25. adigun Orlami January 20, 2020 at 1:18 am - Reply

    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

  26. shantanu sohni January 20, 2020 at 1:18 am - Reply

    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

  27. Esteban Lopez January 20, 2020 at 1:18 am - Reply

    thx bro finally i got how functions really work 🙂

Leave A Comment

*