Learn Python Episode #15: User-Defined Functions

Publié le: 11 août 2017
sur la chaîne: Joseph Delgadillo
3,415
45

Learn Python programming and more with our Learn to Code course Bundle!
⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠⁠https://josephdelgadillo.com/product/...

Let's get into user-defined functions. Now, every programming language has functions, however they are going to look different depending on the language. If you have any experience with PHP or JavaScript, functions in Python are going to look similar. So, we are now past the need to use terminal, and from here on out we are going to use our IDE. In addition to functions, we are going to cover a few of the PEP guidelines. PEP is basically a style guide for the Python language, and the first thing we need to do is drop down two lines from the top of the script. To begin defining a function in Python, all you need to do is type the word "def". When naming functions we must be mindful of the PEP guidelines. With Python you will be using snake case, words separated with underscores, when naming your function.

def my_function():

Within the parenthesis we can pass parameters into our function, then we end the line with a colon. So, now we have a function but it doesn't perform any actions, yet.

def my_function():
print("This is my function!")
print("A second string.")

my_function()

Now our function will print out two strings. Notice that our IDE automatically indents 4 spaces. When you indent in Python you are creating block of code. When we skip a line and remove the indentation, we are telling Python that our function is completed. Lastly, we will call our function. In the next video we will talk about arguments and how use them inside your function.

Web - https://josephdelgadillo.com
Subscribe - https://bit.ly/SubscribeJTD
Facebook -   / delgadillojt  


Sur cette page du site, vous pouvez voir la vidéo en ligne Learn Python Episode #15: User-Defined Functions durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Joseph Delgadillo 11 août 2017, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 3,415 fois et il a aimé 45 téléspectateurs. Bon visionnage!