Python 3 Programming Tutorial – Functions

///Python 3 Programming Tutorial – Functions

Python 3 Programming Tutorial – Functions

FavoriteLoadingAdd to favorites

The idea of a function is to assign a set of code, and possibly variables, known as parameters, to a single bit of text. You can think of it a lot like why you choose to write and save a program, rather than writing out the entire program every time you want to execute it.

To begin a function, the keyword ‘def’ is used to notify python of the impending function definition, which is what def stands for. From there, you type out the name you want to call your function. It is important to choose a unique name, and also one that wont conflict with any other functions you might be using. For example, you wouldn’t want to go calling your function print.

Sample code for this basics series:

Python 3 Programming tutorial Playlist:

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

By |2017-06-05T01:23:07+00:00June 5th, 2017|Python Video Tutorials|18 Comments


  1. Rhiannon Haynes June 5, 2017 at 1:31 am - Reply

  2. SilverRick June 5, 2017 at 1:32 am - Reply

    these videos are really helping me out, thanks for making them!

  3. Sandesh G June 5, 2017 at 1:32 am - Reply

    knock” knock” are you Mr.X )) ((Yes, I am Mr.X . You sound different .

  4. EVDE KSP June 5, 2017 at 1:33 am - Reply

    Hi sentdex, i have a little problem with a piece of code, here is the code:

    def sMenu():
        sMenu1 = input("Select a module: rn – CALMOD (calculator, formula calculator) : type calmod rn – KAPCAL (currency calculator) : type kapcal rn – UNCHE (unit calculator) : type unche rn rn")
        if sMenu1 == "calmod" or "CALMOD":
        elif sMenu1 == "kapcal" or "KAPCAL":
        elif sMenu1 == "unche" or "UNCHE":
            print("Unknown command, try again")

    for some reason when i type kapcal, it still opens calmod, i dont understand what i am doing wrong.


  5. fynn hockenhull June 5, 2017 at 1:35 am - Reply

    you made me do work

  6. fatmandoubblescoop June 5, 2017 at 1:42 am - Reply

    print(‘Your videos are so helpful’)
    print(‘I think i love you??’)

  7. Otsen June 5, 2017 at 1:43 am - Reply

    Some how in this video you sound like other person. Am I the only one who notice this? 😛

  8. ima poop June 5, 2017 at 1:49 am - Reply

    this is a procedure. not a function

  9. Paritosh Ghimire June 5, 2017 at 1:53 am - Reply

    he missed this . A very useful one.
    def function():
    return("full of shit")
    when you call the function , it only prints the value asked.
    when you print the function , it also prints the return value.
    full of shit

  10. Domini Gai June 5, 2017 at 1:58 am - Reply

    Thank you sir

  11. tim mellis June 5, 2017 at 2:02 am - Reply

    I thought we needed to put return in there? I’m confused as hell. Why doesn’t:
    x = 1
    def c():
    return x


    Why doesn’t that work? In other words why doesn’t it print or return 1?

  12. EdgyBacon June 5, 2017 at 2:05 am - Reply

    It says name ‘example’ is not defined. Please help

  13. Shant Kalaidjian June 5, 2017 at 2:09 am - Reply

    Perfect videos we are using them in our school 😉

  14. MyAndroidBite June 5, 2017 at 2:11 am - Reply

    The sound his keystrokes make are just so soothing.

  15. Tinesha Allen June 5, 2017 at 2:13 am - Reply

    hey I have a question about functions, Im trying to write one and then call it in the main but this is what happens , please help

    import math

    def computeLength ():
    height = h
    angle = a
    a = math.radians (a)
    length = (h)/(math.sin (a))
    return length

    def main ():

    print ( "This program computes the length of a ladder needed to reach a house")

    #prompt and read input
    h = eval(input("Enter the height of house in feet" ))
    a = eval(input("Enter the angle between ladder and ground in degrees" ))

    #compute the length of a ladder needed
    length = computeLength
    height = h
    angle = a

    main ()

    #Display the output
    print("/nThe required ladder length is", length)

    this is what it is telling me when I try to run it:

    Traceback (most recent call last):
    File "/Users/TineshaAllen/Desktop/", line 34, in <module>
    print("/nThe required ladder length is", length)
    NameError: name ‘length’ is not defined

  16. Aqua Nightingale June 5, 2017 at 2:20 am - Reply

    sentdex = lifesaver
    I finally know what def mean

  17. Arun Kumar June 5, 2017 at 2:21 am - Reply

    Hi Sentdex,

    I want to watch your first video tutorial. I searched down but didnt please send me a link of the first tutorial. M ew to python I hope you will understand.

  18. Kamil Ziemian June 5, 2017 at 2:21 am - Reply

    Nice example of easy to write functions. I will have unofficial workshop in Python and I will use something like that to teach writting function.

    Thank you for inspiration!

Leave A Comment